c# - How to setting a model with table don't have any primary key column -
on setting dbcontext
, have
modelbuilder.entity<person>(app => { app.totable("person"); });
the efcore throws exception:
the entity type "person" requires primary key defined
but our person
table doesn't have primary key column.
how avoid ?
ef core doesn't support tables without primary keys (aka heaps). reason simple: needs able manipulate individual records, cannot safely achieved without primary key. resolution, can add dummy column/primary key of type int/identity or guid/uniqueidentifier, , ignore it.
wiki
Comments
Post a Comment