Entity structure workaround for displaying on frontend

I want to create a generic way to apply soft delete in my framework application. I have an interface model that defines a remote field:

public interface IModel
{
    bool Deleted { get; set; }
    Nullable<DateTime> Created { get; set; }
    Nullable<DateTime> Modified { get; set; }
}

      

Almost every model in my application implements this IModel

. In order to keep DbContext

all records where true is removed, I want to apply the mapping. I used this good article as the basis for my implementation.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<IModel>()
        .Map(m => m.Requires("Deleted").HasValue(false))
        .Ignore(m => m.Deleted);
}

      

However, mapping to interfaces is (apparently) not supported by the entity framework. This makes me struggle to make it work in such a way that I don't have to apply this mapping on a per-model basis.

Is there another loose API for me to apply mapping across all models that implement IModel

without a lot of extra code?

+1


source to share





All Articles