LINQ to SQL Instantiation
page 8 of 8
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 43439/ 60

Conclusion

I have tried to incorporate some specific detail about the creation of LINQ objects, when the objects are loaded, and discuss how the deferred and immediate loading setup works. I hope this helps when you use LINQ-to-SQL, to understand how objects are instantiated and work with each other.


View Entire Article

User Comments

Title: Another way to do this...?   
Name: Funka!
Date: 2009-08-14 5:17:13 PM
Comment:
Another possibility it seems is to create a partial class and partial method "OnCreated" ?
For example:
public partial class Order
{
partial void OnCreated()
{
_OrderKey = Guid.NewGuid();
_CreatedDate = DateTime.Now;
}
}
This way, you don't need to keep remembering to do this every time you instantiate an object.

It should also be noted that you avoid your specific error (but not the general need for setting default values) by setting the LTS entity property's "Auto Generated Value" to true --- LTS will know not to supply a value to these columns when inserting, so you can just let SQL server fill in these defaults.

Thanks!
-f!
Title: Great Article !!!   
Name: Jash
Date: 2009-04-13 3:24:14 PM
Comment:
Thank you Brian really useful article.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-11-29 6:03:55 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search