I just started to get acquainted with the LINQ technology, specifically DLINQ. It should probably be renamed DIMES (D*** It, Make Everything SQL).
It is definitely going to take some getting used to, but it is a cool concept.
In listing 1, I load a Typed DataSet for the Microsoft Access FPNWIND database using two adapters: ProductsTableAdapter and CustomersTableAdapter. All of the adapter and typed dataset code was generated for me courtesy of Data->Add New Data Source.
My first DLINQ statement gets all the cities fron the Customers table and spits them out to the console.
Here is the link statements. First I constructed a query from a typed data row. Then I performed the LINQ Query and finally I just spit out the results of the query to the console:
Listing 1: Getting Data Into a Query and Using LINQ
var customerQuery = ds.Customers.ToQueryable<LINQConsoleApplication1.FPNWINDDataSet.CustomersRow>;
var query = from customer in customerQuery select customer.City;
Here is the full code for performing the list of cities to the console window:
using System;
using System.Collections.Generic;
using System.Text;
using System.Query;
using System.Xml.XLinq;
using System.Data.DLinq;
using System.Data;
using LINQConsoleApplication1.FPNWINDDataSetTableAdapters;
namespace LINQConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
FPNWINDDataSet ds = new FPNWINDDataSet();
FPNWINDDataSetTableAdapters.CustomersTableAdapter customerAdapter = new CustomersTableAdapter();
FPNWINDDataSetTableAdapters.ProductsTableAdapter productAdapter = new ProductsTableAdapter();
customerAdapter.Fill(ds.Customers);
productAdapter.Fill(ds.Products);
var customerQuery = ds.Customers.ToQueryable<LINQConsoleApplication1.FPNWINDDataSet.CustomersRow>();
var productQuery = ds.Products.ToQueryable<LINQConsoleApplication1.FPNWINDDataSet.ProductsRow>();
var query = from customer in customerQuery select customer.City;
foreach (var item in query)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
What if I only want cities beginning with M? Then try:
var query = from customer in customerQuery where (customer.City[0] == 'M') select customer.City;
What if I want to see company name and the city? Here you go:
var query = from customer in customerQuery where (customer.City[0] == 'M') select customer.CompanyName.PadRight(50) + customer.City;
This gives the output:

What if we want all products that are going to cost us more than 39 dollars? Try:
var query = from product in productQuery where (product.UnitPrice > 39) select product.ProductName.PadRight(50) + product.UnitPrice;

Stay tuned for more fun with LINQ where we use the relationship between two tables to get our data.
-Mike

Mike GoldPosted Jun 22, 2007, 3:05 PM
I actually generated the connection string from the Server Explorer, so I had to look. It seems the connection string is generated in the appsettings file: LINQConsoleApplication1\Properties\Settings.Designer.cs(29): [global::System.Configuration.DefaultSettingValueAttribute("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\FPNWIND.MDB")] public string FPNWINDConnectionString { get { return ((string)(this["FPNWINDConnectionString"])); } } As well as the XSD which generates this code: <Connection AppSettingsObjectName="Settings" AppSettingsPropertyName="FPNWINDConnectionString" ConnectionStringObject="" IsAppSettingsProperty="True" Modifier="Assembly" Name="FPNWINDConnectionString (Settings)" PropertyReference="ApplicationSettings.LINQConsoleApplication1.Properties.Settings.GlobalReference.Default.FPNWINDConnectionString" Provider="System.Data.OleDb"> All the actual connecting to the database seems to be generated from the xsd and stored in the designer cs file.
Mahesh ChandPosted Jun 22, 2007, 11:18 AM
Mike, This actually could be an article ;). Is there any concept of database connection string? Where do you specify that? Can you send me the source code? Thanks, Mahesh