How to setting a model with table don't have any primary key column

.net-standard asp.net-core c# entity-framework entity-framework-core

Question

On setting DbContext, we have

modelBuilder.Entity<Person>(app =>
{
    app.ToTable("Person");
});

The EFCore throws an exception:

The entity type "Person" requires a primary key to be defined

But our Person table doesn't have any primary key column.

How to avoid this ?

1
1
8/22/2017 9:30:13 AM

Popular Answer

EF Core doesn't support tables without primary keys (aka heaps). The reason is simple: it needs to be able to manipulate individual records, something that cannot be safely achieved without a primary key. As a resolution, you can add a dummy column/primary key of type int/identity or guid/uniqueidentifier, and just ignore it.

4
8/22/2017 9:18:15 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow