user738383
user738383

Reputation: 607

The DataContext object (LINQ to SQL)

I've read about ways to synch my SQL database with my C# code, and it looks like the DataContext object is the way I'm going to go.

After having read up on what it can do, I find myself still slightly confused on its exact capabilities. For instance, once set up, does the DataContext linked to my SQL database contain a property for each table? And does that table object then contain a list of items, each of which holds the data for each table entry?

In addition, I'm not sure how to instruct it to generate me the code (since I've read that it does generate the necessary objects). How is this achieved?

Upvotes: 0

Views: 4744

Answers (3)

huMpty duMpty
huMpty duMpty

Reputation: 14460

"does the DataContext linked to my SQL database contain a property for each table"
 YES you will be able to accesss all the table and properties, 
 that you have used in your datacontext (.dbml) file

Anyway, please read this article about LINQ TO SQL. Also there are some good video tutorial about ASP.NET 3.5 LINQ TO SQL

Hope this help

Upvotes: 1

Anders Abel
Anders Abel

Reputation: 69260

What have you tried so far?

There are two ways to generate the code:

  • In Visual Studio, on your project, add a new item of type "LINQ to SQL classes". Then drag-and-drop the tables you want in your project onto the drawing space. This is the most simple, but there is no support for refreshing the model if you change the database.
  • Use the commandline tool SqlMetal.exe to generate the classes.

Upvotes: 0

Roy Dictus
Roy Dictus

Reputation: 33139

The Gu (Scott Guthrie) has an excellent article series about Linq to Sql that introduces this concept: http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

Good luck!

Upvotes: 3

Related Questions