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

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: 2010-11-08 4:24:52 AM
hi ...this example was good...your practical approach was good..
Title: sample code   
Name: SirReadALOT
Date: 2010-04-08 6:49:21 PM
hi would it be possible to downlad the application?
Title: stored procedure   
Name: pappu reddy
Date: 2009-03-18 6:09:56 AM
can u give any other implementation

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

©Copyright 1998-2024  |  Page Processed at 2024-05-25 11:52:24 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search