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:
'DataRecord' does not implement interface member 'IAuditable.ChangedDate'.
Hello:)
This means your DataRecord class hasn't got a method that comes from IAuditable.ChangedDate。
erwee
'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。)
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?
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
erwee
Member
9 Points
6 Posts
Audit by using CreatedDateTime, CreatedBy
Dec 01, 2011 12:56 PM|LINK
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
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Audit by using CreatedDateTime, CreatedBy
Dec 03, 2011 01:11 AM|LINK
Hello:)
This means your DataRecord class hasn't got a method that comes from IAuditable.ChangedDate。
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!
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Audit by using CreatedDateTime, CreatedBy
Dec 03, 2011 12:16 PM|LINK
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?
Always seeking an elegant solution.