locked
Audit by using CreatedDateTime, CreatedBy RRS feed

  • Question

  • User233555810 posted

    This is a question regarding an answer on a previous post entitled:
    CreatedDateTime, CreatedBy, UpdatedDateTime and UpdatedBy

    I’ve implemented the code “ A Method to Handle Audit Fields in LINQ to SQL” mentioned above and it works perfectly for “string” values. When I try referencing a “date” column, I keep getting the following error:

     'DataRecord' does not implement interface member 'IAuditable.ChangedDate'. 'DataRecord.ChangedDate' cannot implement 'IAuditable.ChangedDate' because it does not have the matching return type of 'System.DateTime'.

     I’ve tried different date types in SQL 2008 (date / datetime / datetime2). I’ve tried changing the type in the interface to different data types (System.Data.SqlTypes.SqlDateTime). I’ve even tried converting between date types in “ProcessAuditFields” but with no luck.

    I’m probably doing something really silly, but I just can’t seem to find it.I have a table with multiple columns, including 2 for audit. The Audit columns are called: ChangedDate (datetime) and ChangedUser (nvarchar(50)). Code:

     

        internal interface IAuditable 
        { 
             
            string ChangedUser { get; set; } 
            DateTime ChangedDate { get; set; } 
     
        } 
     
            private static void ProcessAuditFields(IList<System.Object> list) 
            { 
                foreach (var item in list) 
                { 
                    IAuditable entity = item as IAuditable; 
                    if (entity != null) 
                    { 
               
                            entity.ChangedUser = GetUserName(); 
                            entity.ChangedDate = DateTime.Now; 
     
                
                    } 
                } 
            }

    I treat both INSERTS and UPDATES the same.

    Does anyone have any ideas?

    Many thanks

    Thursday, December 1, 2011 8:56 AM

Answers

  • User3866881 posted

    'DataRecord' does not implement interface member 'IAuditable.ChangedDate'.

    Hello:)

    This means your DataRecord class hasn't got a method that comes from IAuditable.ChangedDate。

    'DataRecord.ChangedDate' cannot implement 'IAuditable.ChangedDate' because it does not have the matching return type of 'System.DateTime'.

    Please check whether your ChangedData is THE SAME AS WHAT you've defined in the interface's method(Must be the same name,same parameters in number,order and types,and your return type should be also the same。)

    Best reguards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 2, 2011 9:11 PM

All replies

  • User3866881 posted

    'DataRecord' does not implement interface member 'IAuditable.ChangedDate'.

    Hello:)

    This means your DataRecord class hasn't got a method that comes from IAuditable.ChangedDate。

    'DataRecord.ChangedDate' cannot implement 'IAuditable.ChangedDate' because it does not have the matching return type of 'System.DateTime'.

    Please check whether your ChangedData is THE SAME AS WHAT you've defined in the interface's method(Must be the same name,same parameters in number,order and types,and your return type should be also the same。)

    Best reguards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 2, 2011 9:11 PM
  • User-330204900 posted

    Hi Erwee, I use this all the time with EF mostly now but have recently implemented in L2S. Can you post you metadata classes please (what you are applying the IAuditable interface). also can you identify what line the error occurs on, is it in the model or the helper?

    Saturday, December 3, 2011 8:16 AM