问题
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