2016-11-20 9 views
1

監査ログを自動的に書き込む方法はありますか? 私はここでDbSet(Of Protocols)エンティティフレームワークコア - 監査

を作成しましたが、私のプロトコルクラスです:

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をSaveChangesメソッドに入れて、プロトコルクラスのCreatedByUserIdプロパティを入力するにはどうすればよいですか? 誰かがそれを自動的に行う考えがあるかもしれません。

答えて

1

DbContextを継承したカスタムDBコンテキストを作成し、変更前/後のデータを操作できるようにSaveChanges()メソッドをオーバーライドできます。

Audit.EntityFrameworkなどのライブラリを使用するか、コードを確認してください(C#申し訳ありません)。

また、ライブラリEntityFramework-Plusはおそらく役に立ちます。