有没有办法自动编写审核日志?
我创建了一个 Public Class Protocol
Inherits ModelBase
Implements ILogicalTimestamp
<Key>
Public Property ProtocolId As Integer
<Required>
Public Property ProtocolText As String
Public Property CreatedByUserId As Integer?
<Required>
Public Property CreatedByUser As User
<Required>
<DefaultValue(0)>
Public Property Type As ProtocolType
Public Property LinkedToUserId As Integer?
Public Property LinkedToUser As User
Public Property LinkedToBusinessPartnerId As Integer?
Public Property LinkedToBusinessPartner As BusinessPartner
Public Property LinkedToClientId As Integer?
Public Property LinkedToClient As Client
Public Property LinkedToSettingId As Integer?
Public Property LinkedToSetting As Setting
Public Property LastUpdateTimestamp As Date? Implements ILogicalTimestamp.LastUpdateTimestamp
Public Property CreationTimestamp As Date? Implements ILogicalTimestamp.CreationTimestamp
Public Enum ProtocolType
AutoChanges = 0
Explicitly = 1
End Enum
End Class
这是我的协议类:
UserId
如何在协议中编写更改?
如何将当前CreatedByUserId
放入SaveChanges方法以填充我的协议类中的{{1}}属性?
也许任何人都有自己的想法。
答案 0 :(得分:1)
您可以创建从DbContext
继承的自定义数据库上下文,然后覆盖SaveChanges()方法,这样您就可以在修改之前/之后操作数据。
或者您可以使用Audit.EntityFramework之类的库,或查看其代码(C#抱歉)。
图书馆EntityFramework-Plus也可以提供帮助。