The generated LinqToSql code provides extensibility points, so you can set values when the objects are loaded.
The key is to create a partial class which extends the generated class, and then implement the OnLoaded
partial method.
For instance, let's say your class is Person
, so you have a generated partial Person
class in Blah.designer.cs
.
Extend the partial class by creating a new class (must be in a different file), as follows:
public partial class Person {
partial void OnLoaded() {
this._BirthDate = DateTime.SpecifyKind(this._BirthDate, DateTimeKind.Utc);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…