Tuesday, February 19, 2008

How to autogenerate PK - Guid and other default properties in your LINQ class

partial class Invitation
{
partial void OnCreated()
{
if (Id == Guid.Empty)
{
this.Id = Guid.NewGuid();
this.CreatedDate = DateTime.Now;
}
}

}
Also in this sample I am setting CreatedDate for my objects. Works fine.




Applies to all dotnet languages: C#, VB.NET, C++.NET, J#

Labels:

1 Comments:

At 6:33 AM, Anonymous Evelyn said...

Good words.

 

Post a Comment

<< Home