As of EF6 it is possible to do something like this when configuring Entity mappings using Table Per Hierarchy inheritance:
public class MyContext : DbContext
{
public DbSet<Device> Devices { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<ABatteryPoweredDevice>().Property(c => c.BatteryLevel).HasColumnName("BatteryLevel");
modelBuilder.Entity<ADifferentBatteryPoweredDevice>().Property(c => c.BatteryLevel).HasColumnName("BatteryLevel");
}
}
BatteryLevel
is not part of the Device
base class- it is a property of the derived classes implemented to fulfill an interface contract.
Is it possible to make this the default behavior as opposed to having to add a new mapping for each derived class?