LINQ to SQL Instantiation
page 1 of 8
Published: 09 May 2008
This article discusses how and when the objects within LINQ to SQL are created and instantiated, and how it maintains a list of the changes that need submitted to the database. It also discusses how this can be managed and some of the intricacies in LINQ with the help of source code.
by Brian Mains
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 41064/ 47


LINQ to SQL is an ORM tool that connects to SQL Server databases. It generates business objects to match a database's table structures, which are all centrally available through the DataContext class. The LINQ-to-SQL designer creates a custom DataContext class that contains a series of Table<Entity> objects representing each of the tables in your database.

LINQ to SQL makes it easier to create application architecture, with some caveats (what doesn't have any in life?).

View Entire Article

User Comments

Title: Another way to do this...?   
Name: Funka!
Date: 2009-08-14 5:17:13 PM
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.

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

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

©Copyright 1998-2024  |  Page Processed at 2024-04-13 9:29:25 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search