Database-> DataSet-> Typed DataSet-> ADO. NET Entity Framework-> LINQ.
Add a typed dataset by Main Menu-> Data-> Add Data Source.
Using NorthwindDataSetTableAdapters;
NorthwindDataSet ds = new NorthwindDataSet ();
TableAdapterManager adapters = new TableAdapterManager ();
Adapters. CustomersTableAdapter = new CustomersTableAdapter ();
Adapters. OrdersTableAdapter = new OrdersTableAdapter ();
Adapters. Order_DetailsTableAdapter = new Order_DetailsTableAdapter ();
Adapters. ProductsTableAdapter = new ProductsTableAdapter ();
Adapters. CustomersTableAdapter. Fill (ds. MERs mers );
Adapters. OrdersTableAdapter. Fill (ds. Orders );
Adapters. Order_DetailsTableAdapter.Fill (ds. Order_Details );
Adapters. ProductsTableAdapter. Fill (ds. Products );
// Direct
Console. WriteLine ("Direct -------------------------------------------");
Foreach (var row in ds. MERs mers)
If (row. Country = "USA ")
Console. WriteLine (new {row. CustomerID, row. Country, row. ContactName });
// LINQ to Object
Var query = ds. MERs
. Where (c => c. Country = "USA ")
. Select (c => new {c. CustomerID, c. Country, c. ContactName });
Console. WriteLine ();
Console. WriteLine ("LINQ to Object ------------------------------------");
Foreach (var row in query)
Console. WriteLine (row );
// LINQ to DataSet
DataTable customersTable = (DataTable) ds. MERs MERS;
Var query2 =
From c in customersTable. AsEnumerable ()
Where c. Field <string> ("Country") = "USA"
Select c;
Console. WriteLine ();
Console. WriteLine ("LINQ to DataSet ------------------------------------");
Foreach (var row in query2)
Console. WriteLine (new
{
CustomerID = row. Field <string> ("CustomerID "),
Country = row. Field <string> ("Country "),
ContactName = row. Field <string> ("ContactName ")
});
If you create the typed DataSet with Visual Studio, your typed DataTable classes will be derived from the TypedTableBase <T> class, which implements the IEnumerable <T> interface. for this reason, it is not required to call AsEnumerable to get a wrapper. var query2 =
// From c in customersTable. AsEnumerable ()
From c in ds. MERs
Where c. Field <string> ("Country") = "USA"
Select c;
Reference
MSDN: LINQ to DataSet
Http://msdn.microsoft.com/en-us/library/bb386977.aspx