Using LINQ to SQL - Part 2
page 4 of 11
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 49634/ 129

Creating Entity Classes from a Database

If you already have a database schema defined, you can use it to quickly create LINQ to SQL entity classes modeled off of it.

The easiest way to accomplish this is to open up a database in the Server Explorer within Visual Studio, select the Tables and Views you want to model in it, and drag/drop them onto the LINQ to SQL designer surface:

Figure 4

When you add the above 2 tables (Categories and Products) and 1 view (Invoices) from the "Northwind" database onto the LINQ to SQL designer surface, you'll automatically have the following three entity classes created for you based on the database schema:

Figure 5

Using the data model classes defined above, I can now run all of the code samples (expect the SPROC one) described in Part 1 of this LINQ to SQL series.  I don't need to add any additional code or configuration in order to enable these query, insert, update, delete, and server-side paging scenarios. 


View Entire Article

User Comments

Title: LInq to Sql   
Name: praveen
Date: 11/8/2010 4:24:52 AM
Comment:
hi ...this example was good...your practical approach was good..
Title: sample code   
Name: SirReadALOT
Date: 4/8/2010 6:49:21 PM
Comment:
hi would it be possible to downlad the application?
Title: stored procedure   
Name: pappu reddy
Date: 3/18/2009 6:09:56 AM
Comment:
can u give any other implementation






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


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 9/21/2014 2:08:55 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search