Ignore base class / interfaces completely in entity framework 5 code first

本秂侑毒 提交于 2019-12-24 02:23:22

问题


I have the following entity class:

[System.ComponentModel.DataAnnotations.Schema.Table("User")]
public class User: UserBase, IPersistCustom<Entity> { ... }

Depending on the type of hierarchy mapping you use, EF will generate either a descriptor column or split tables. Is there a way to have EF completely ignore the fact that this class inherits from something or implements an interface?

I don't mean just ignoring base class properties.


回答1:


If you mark your base class(es) as abstract and use table per concrete type approach this may work. Something like;

context.Entity<User>().Map(p =>
        {
            p.MapInheritedProperties();
            p.ToTable("Users");
        });           

refer to this.




回答2:


are you looking for this.... fluent API option

 modelBuilder.Entity<XYZ>().Ignore(p => p.PropertyName);


来源:https://stackoverflow.com/questions/14636222/ignore-base-class-interfaces-completely-in-entity-framework-5-code-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!