I add a discriminator column to all my entities in order to facilitate soft delete.
Currently I do it by specifying it on each entity one by one:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Foo>().Map(m => m.Requires("IsDeleted").HasValue(false));
modelBuilder.Entity<Bar>().Map(m => m.Requires("IsDeleted").HasValue(false));
//etc etc
}
What I'd like to be able to do is specify it as a Custom Code First Convention. My entities all inherit from a ModelBase
class. So I can create a custom convention to map to stored procedures like this:
modelBuilder.Types<ModelBase>().Configure(m => m.MapToStoredProcedures());
but this is not available:
modelBuilder.Types<ModelBase>().Configure(m => m.Requires("IsDeleted").HasValue(false));
So, is there any way to add a discriminator to all entities that inherit from ModelBase
other than doing it one by one?