EF SaveChanges重写加入日志
程序员文章站
2022-04-15 21:27:54
public override int SaveChanges() { var entries = ChangeTracker.Entries().Where(x => x.State != EntityState.Unchanged).GroupBy(x => new { x.State, x.E ......
public override int savechanges() { var entries = changetracker.entries().where(x => x.state != entitystate.unchanged).groupby(x => new { x.state, x.entity.gettype().name }).select(x => new { x.key.state, x.key.name, list = x.tolist() }); jsonserializersettings settings = new jsonserializersettings { referenceloophandling = referenceloophandling.ignore// 发现循环引用时跳过序列化 }; foreach (var item in entries) { logger.writeoperationlog($"\r\n operation {item.state} date:{datetime.now.tostring("yyyy-mm-dd hh:mm:ss")}\r\n entity:{item.name}\r\n data:{jsonconvert.serializeobject(item.list.select(x => x.entity).tolist(), settings)}", "default"); } return base.savechanges(); }
上一篇: PHP使用Redis的事务命令
下一篇: Android连载8-动态的添加碎片