I have implemented a database soft delete (a boolean flag that marks entries as deleted) using the following tutorial: http://www.codeguru.com/csharp/csharp/soft-deleting-en
There is a bug in ApplicationDbContext.cs:
protected new void OnModelCreating(DbModelBuilder modelBuilder) {...}
You are using "new" instead of "override" so OnModelCreating is never executed (try to add a breakpoint to check it). So AttributeToTableAnnotationConvention never runs and entity annotation is never added.
Changing it to
protected override void OnModelCreating(DbModelBuilder modelBuilder) {...}
will make it work
Well, you code seems fine to me. Perhaps there is a little mistake that is breaking your app. You could try this:
Remove the SoftDeleteAttribute
from BC_Instance
Edit the OnModelCreating
method
AttributeToTableAnnotationConvention<SoftDeleteAttribute, string> conv =
new AttributeToTableAnnotationConvention<SoftDeleteAttribute, string>(
"SoftDeleteColumnName",
(type, attributes) => attributes.Single().ColumnName);
modelBuilder.Conventions.Add(conv);
//this will dynamically add the attribute to all models
modelBuilder.Types().Configure(delegate(ConventionTypeConfiguration i)
{
i.HasTableAnnotation("SoftDeleteColumnName", Entity.G etSoftDeleteColumnName());
});
Delete ApplicationDbConfiguration
class
Edit the context's constructor
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
DbInterception.Add(new SoftDeleteInterceptor());
}
Hope this helps!