实体框架:创建更改历史记录
我有一个 EDM (phoneDB),它对后端 MSSQL 数据库进行建模。我开发了一个 ASP.NET (VB) 应用程序,允许用户编辑该数据库中的信息。当有人编辑记录条目时,我想记录此操作。
现在,我正在执行以下操作:
For Each..Next 检查条目是否是已修改其实体状态的对象。
如果不是..结束如果这确保我们没有处理关系实体或空实体。
现在这就是它变得模糊的地方。我想要做的就是从这些修改的对象中获取信息并将它们记录到数据库中。现在我有这样的事情:
Dim audit as History
audit.action = "Changed information in " & propName & " to " & entry.CurrentValues(propName) & " from " & entry.OriginalValues(propName)
audit.action_by = this_user
audit.action_date = Date.Now
audit.extension_id =
但是,我不确定如何告诉它从条目中提取特定的属性。例如,我需要获取(伪代码)类似的内容:
audit.extension_id = entry.OriginalValues(extension_id)
I have a EDM (phoneDB) that models a back-end MSSQL database. I've developed a ASP.NET (VB) application that allows one to edit the information in this database. When someone edits a record entry I'd like to record this action.
Right now, I'm doing the following:
For Each..Next that checks whether entry is an object that has had its entitystate modified.
And If Not..End If that ensures we aren't dealing with a relationship entity or a null entity.
Now this is where it gets fuzzy. What I want to do is grab the information from these modified objects and record them into the database. Now I have something like this:
Dim audit as History
audit.action = "Changed information in " & propName & " to " & entry.CurrentValues(propName) & " from " & entry.OriginalValues(propName)
audit.action_by = this_user
audit.action_date = Date.Now
audit.extension_id =
I'm not sure, however, how to tell it to pull a specific property from entry. For example, I need to get (pseudo-code) something like:
audit.extension_id = entry.OriginalValues(extension_id)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白“从条目中提取特定属性”是什么意思?您编写的(伪)代码并不能说明什么,您的情况下的 extesion_id 是什么?如果extension_id是实体的属性名称,那么您可以通过调用entry.OriginalValues(“extension_id”)来获取它的原始值,但我相当确定您知道这一点。
顺便说一句,您可以使用触发器在数据库本身中进行复杂的历史记录,而数据层甚至不知道这一点。这是一个相当古老的技巧,而且工作速度很快,请参阅 这个
I don't understand what do you mean by "pulling a specific property from an entry"? The (pseudo) code you wrote is not telling much, what is an extesion_id in your case? If extension_id is a property name of an entity, then you obtain it's original value by calling entry.OriginalValues("extension_id"), but I'm fairly sure you knew that.
Btw, you can do intricate history recording in the DB itself using triggers without the data layer even knowing it. It's a fairly old trick and works fast, see this
这是我最终完成的方法:
Here is how I accomplished it in the end: