15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

OC260 ❘ ChaPTer 56 linQ tO sQl<br />

figure 56-6<br />

With this action, a bunch of code is added to the designer files of the .dbml file on your behalf. These<br />

classes will give you a strongly typed access to the Products table. For a demonstration of this, turn your<br />

attention to the console application’s Program.cs file. The following shows the code that is required for<br />

this example:<br />

using System;<br />

using System.Linq;<br />

namespace ConsoleApplication1<br />

{<br />

class Class1<br />

{<br />

static void Main(string[] args)<br />

{<br />

NorthwindDataContext dc = new NorthwindDataContext();<br />

var query = dc.Products;<br />

foreach (Product item in query)<br />

{<br />

Console.WriteLine("{0} | {1} | {2}",<br />

item.ProductID, item.ProductName, item.UnitsInStock);<br />

}<br />

}<br />

}<br />

}<br />

Console.ReadLine();<br />

code download ConsoleApplication1.sln<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!