Audit by using CreatedDateTime, CreatedByhttp://forums.asp.net/t/1745346.aspx/1?Audit+by+using+CreatedDateTime+CreatedBySat, 03 Dec 2011 12:16:42 -050017453464710525http://forums.asp.net/p/1745346/4710525.aspx/1?Audit+by+using+CreatedDateTime+CreatedByAudit by using CreatedDateTime, CreatedBy <p>This is a question regarding an answer on a previous post entitled:<br> <a href="../../../../t/1622828.aspx/1?CreatedDateTime&#43;CreatedBy&#43;UpdatedDateTime&#43;and&#43;UpdatedBy" target="_blank">CreatedDateTime, CreatedBy, UpdatedDateTime and UpdatedBy</a></p> <p>Ive implemented the code &nbsp;<a href="http://weblogs.asp.net/stevesheldon/archive/2008/02/23/a-method-to-handle-audit-fields-using-linq-to-sql.aspx">A Method to Handle Audit Fields in LINQ to SQL</a> mentioned above and it works perfectly for string values. When I try referencing a date column, I keep getting the following error:</p> <p>&nbsp;<b><i>'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></b></p> <p>&nbsp;Ive tried different date types in SQL 2008 (date / datetime / datetime2). Ive tried changing the type in the interface to different data types (System.Data.SqlTypes.SqlDateTime). Ive even tried converting between date types in ProcessAuditFields but with no luck.</p> <p>Im probably doing something really silly, but I just cant seem to find it.I&nbsp;have a table with multiple columns, including 2 for audit. The Audit columns are called: <b>ChangedDate</b> (datetime) and <b>ChangedUser </b>(nvarchar(50)). Code:</p> <p>&nbsp;</p> <pre class="prettyprint">internal interface IAuditable { string ChangedUser { get; set; } DateTime ChangedDate { get; set; } } private static void ProcessAuditFields(IList&lt;System.Object&gt; list) { foreach (var item in list) { IAuditable entity = item as IAuditable; if (entity != null) { entity.ChangedUser = GetUserName(); entity.ChangedDate = DateTime.Now; } } }</pre> <p>I treat both INSERTS and UPDATES the same.</p> <p>Does anyone&nbsp;have any ideas?</p> <p>Many thanks</p> 2011-12-01T12:56:01-05:004713084http://forums.asp.net/p/1745346/4713084.aspx/1?Re+Audit+by+using+CreatedDateTime+CreatedByRe: Audit by using CreatedDateTime, CreatedBy <p></p> <blockquote><span class="icon-blockquote"></span> <h4>erwee</h4> 'DataRecord' does not implement interface member 'IAuditable.ChangedDate'.</blockquote> <p></p> <p>Hello</p> <p>This means your DataRecord class hasn't got a&nbsp;method that comes from IAuditable.ChangedDate</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>erwee</h4> 'DataRecord.ChangedDate' cannot implement 'IAuditable.ChangedDate' because it does not have the matching return type of 'System.DateTime'.</blockquote> <p></p> <p>Please check whether your ChangedData is THE SAME AS WHAT you've defined in the interface's method(Must be the same namesame parameters in numberorder and typesand your return type should be also the same)</p> <p>Best reguards</p> 2011-12-03T01:11:36-05:004713596http://forums.asp.net/p/1745346/4713596.aspx/1?Re+Audit+by+using+CreatedDateTime+CreatedByRe: Audit by using CreatedDateTime, CreatedBy <p>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?</p> 2011-12-03T12:16:42-05:00