کتابخانه ای برای ایجاد Interception در EF به زبان ساده تر
نویسنده: علی یگانه مقدم
تاریخ: ۱۳۹۷/۰۸/۰۷ ۱۰:۲۶
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
public class AuditInterceptor : Interceptor<IAuditEntity>
{
public override void PreInsert(IContext<IAuditEntity> context)
{
context.Entity.CreatedAt = DateTime.UtcNow;
context.Entity.ModifiedAt = DateTime.UtcNow;
}
public override void PreUpdate(IContext<IAuditEntity> context)
{
context.Entity.ModifiedAt = DateTime.UtcNow;
}
}
public class MyDbContext : InterceptionDbContext
{
public MyDbContext()
{
AddInterceptor(new AuditInterceptor());
}
}