title: LINQ2SQL: How to modify fields values when loading anonymous entities?
body: <p><strong>!!! Please do not redirect to <a href="https://stackoverflow.com/questions/823313/linq-to-sql-datetime-values-are-local-kind-unspecified-how-do-i-make-it-utc">this article</a>, as it does not solve the problem described below.</strong></p>
  
  <p>Let's say we have such table in database:</p>
  
  <p><strong>SomeTable</strong></p>
  
  <ul>
  <li>ID (int)</li>
  <li>DT (datetime)</li>
  </ul>
  
  <p>We have configured a Linq2Sql data context. And we have configured an entity for SomeTable: <strong>OnLoaded</strong> method modifies DT in such way that DateTimeKind of DT becomes Utc (initially it is Unspecified).</p>
  
  <p>Now here is the problem:</p>
  
  <p>If we request data by using whole entity, the OnLoaded method is called: </p>
  
  <pre><code>From x In ourDataContext.SomeTable Select x
  </code></pre>
  
  <p>But if we request only part of table (and therefore generate an anonymous type), the OnLoaded is not called:</p>
  
  <pre><code>From x In ourDataContext.SomeTable Select x.DT
  </code></pre>
  
  <p>It is clear that OnLoaded is defined in SomeTable entity, and not in anonymous type. </p>
  
  <p>At the moment I consider creating custom entities which would replace anonymous types. But maybe somebody has better solution?</p>