2016-11-20 1 views
1

감사 로그를 자동으로 작성하는 방법이 있습니까? 내가 생성 한 다음 DbSet(Of Protocols)Entity Framework 핵심 감사

내 프로토콜 클래스 : 프로토콜의

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# sorry)를 확인할 수 있습니다.

또한 라이브러리 EntityFramework-Plus이 도움이 될 수 있습니다.

관련 문제