I have a base object that I dont want to be mapped in DB as an entity, I only want the properties to be added to the object that is mapped in the DB :
Not mapped object
Morteza Manavi has a blog post detailing how to do this:
http://weblogs.asp.net/manavi/archive/2011/01/03/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-3-table-per-concrete-type-tpc-and-choosing-strategy-guidelines.aspx
Basically, you'll need to override OnModelCreating
in your DbContext
and call MapInheritedProperties()
for each of the child tables.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("BankAccounts");
});
modelBuilder.Entity().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("CreditCards");
});
}