Map derived type to the same table in EF

后端 未结 3 1268
刺人心
刺人心 2021-01-23 23:11

The following simple code example illustrates the scenario in question. I have a Person entity, which is simply mapped to the Person table in the DB. I am using the default Enti

3条回答
  •  失恋的感觉
    2021-01-23 23:29

    You can add your properties to the class and "ignore" them for the entity framework using the modelBuilder, looks like you doing code first development. For that options have a look at the modelBuilder =>

        public class Db : DbContext
        {
          public DbSet MyClasses{ get; set; }
    
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
            modelBuilder.Entity().Ignore(x => x.MyProperty);
          }
        }
    

    hope this helps!

提交回复
热议问题