实体框架:设置更新时间戳 [英] Entity Framework: Setting update timestamp

查看:61
本文介绍了实体框架:设置更新时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们所有的数据库表都有UpdateUserID和UpdateTS。如果我的实体有更改,我想进行设置。有什么方法可以让我有条件地当场进行此更新吗?

All of our database tables have UpdateUserID and UpdateTS. I'd like to have this set if my entity has changes. Is there a way I can have this update on the spot conditionally?

如果我在代码中手动设置UpdateTS,那么它将表明我的实体已更改并且将始终更新对象。

If I manually set UpdateTS in code, then it will say that my entity has changed and will always update the object.

推荐答案

您应该能够处理SavingChanges事件(此处的示例)并执行@sander概述的逻辑

You should be able to handle the SavingChanges event (example here) and perform logic as outlined by @sander

这篇关于实体框架:设置更新时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆