Entity Framework soft delete implementation using database interceptor not working

前端 未结 2 823
面向向阳花
面向向阳花 2021-01-05 01:38

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

2条回答
  •  悲&欢浪女
    2021-01-05 01:45

    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

提交回复
热议问题