Entity Framework 4.1 Code First: Get all Entities with a specific base class

假装没事ソ 提交于 2019-12-03 13:37:55

You need to introduce TPC inheritance. After that DbContext.Set<Entity>() will work and you will still have table per entity.

Just to your problem in your Edit section:

The error message indicates that you have the Id key property in your base class Entity. Then you need to configure the key property on this class and not on the derived Foo class:

modelBuilder.Entity<Entity>()
    .Property(x => x.Id)
    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!