Error: the entity type requires a primary key

后端 未结 11 1592
走了就别回头了
走了就别回头了 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:53

    When I used the Scaffold-DbContext command, it didn't include the "[key]" annotation in the model files or the "entity.HasKey(..)" entry in the "modelBuilder.Entity" blocks. My solution was to add a line like this in every "modelBuilder.Entity" block in the *Context.cs file:

    entity.HasKey(X => x.Id);
    

    I'm not saying this is better, or even the right way. I'm just saying that it worked for me.

提交回复
热议问题