I'm trying to implement the Soft Delete pattern using the following approach: https://stackoverflow.com/a/18985828/213725
However I have difficulties implement it for Table Per Type inheritance. Let's say I have Entity
mapped to table "Entity" and its descendant ConcreteEntity
mapped to table "ConcreteEntity". I have the IsDeleted
column in the table "Entity" to designate whether the entity is "deleted" or not.
What I trying to do in OnModelCreating
is something like the following:
modelBuilder.Entity<Entity>()
.Map<Entity>(m =>
{
m.ToTable("Entity");
m.Requires("IsDeleted").HasValue(false);
})
.Map<ConcreteEntity>(m =>
{
m.ToTable("ConcreteEntity");
});
I doesn't work though. I'm getting the following error:
(59,10) : error 3032: Problem in mapping fragments starting at lines 59, 142:EntityTypes Entity, ConcreteEntity are being mapped to the same rows in table Entity. Mapping conditions can be used to distinguish the rows that these types are mapped to.
Any ideas what I'm doing wrong?