!!! Please do not redirect to this article, as it does not solve the problem described below.
Let's say we have such table in database:
SomeTable
- ID (int)
- DT (datetime)
We have configured a Linq2Sql data context. And we have configured an entity for SomeTable: OnLoaded method modifies DT in such way that DateTimeKind of DT becomes Utc (initially it is Unspecified).
Now here is the problem:
If we request data by using whole entity, the OnLoaded method is called:
From x In ourDataContext.SomeTable Select x
But if we request only part of table (and therefore generate an anonymous type), the OnLoaded is not called:
From x In ourDataContext.SomeTable Select x.DT
It is clear that OnLoaded is defined in SomeTable entity, and not in anonymous type.
At the moment I consider creating custom entities which would replace anonymous types. But maybe somebody has better solution?