Error: the entity type requires a primary key

后端 未结 11 1583
走了就别回头了
走了就别回头了 2020-12-02 15:30

I would like to expand the question asked on this thread

Binding listbox to observablecollection

by giving it an ability to persistent the data. The structur

11条回答
  •  离开以前
    2020-12-02 15:48

    Your Id property needs to have a setter. However the setter can be private. The [Key] attribute is not necessary if the property is named "Id" as it will find it through the naming convention where it looks for a key with the name "Id".

    public Guid Id { get; }              // Will not work
    public Guid Id { get; set; }         // Will work
    public Guid Id { get; private set; } // Will also work
    

提交回复
热议问题