Database Reference
In-Depth Information
How It Works
You declare a string array called names .
string[] names = {"Life is Beautiful",
"Arshika Agarwal",
"Seven Pounds",
"Rupali Agarwal",
"Pearl Solutions",
"Vamika Agarwal",
"Vidya Vrat Agarwal",
"Lionbridge Technologies" };
To retrieve names from the string array, you query the string array using IEnumerable<string> and
also loop through the names array with the help of foreach using the LINQ to Objects query syntax.
IEnumerable<string> namesOfPeople = from name in names
where name.Length <= 16
select name; foreach (var name in namesOfPeople)
Using LINQ to SQL
LINQ to SQL is a facility for managing and accessing relational data as objects. It's logically similar to
ADO.NET in some ways, but it views data from a more abstract perspective that simplifies many
operations. It connects to a database, converts LINQ constructs into SQL, submits the SQL, transforms
results into objects, and even tracks changes and automatically requests database updates.
A simple LINQ query requires three things:
Entity classes
A data context
A LINQ query
Try It: Coding a Simple LINQ to SQL Query
In this exercise, you'll use LINQ to SQL to retrieve all contact details from the AdventureWorks
Person.Contact table.
1. Navigate to Solution Explorer, right-click the Linq project, and select Add
Windows Form. In the opened Add New Item dialog, make sure Windows
Form is selected and then rename Form1.cs to LinqToSql. Click Add.
2. Select the LinqToSql form by clicking the form's title bar, and set the Size
property's Width to 355 and Height to 386.
3. Drag a TextBox control onto the form, and position it toward the center of the
form. Select this TextBox, navigate to the Properties window, and set the
following properties:
Set the Name property to txtLinqToSql.
Set the Multiline property to True.
 
Search WWH ::




Custom Search