Blog Map
[Blog Map] This blog is inactive. New blog: EricWhite.com/blog
Every now and then, I need to have a source of data for an example or proof of concept that I’m building. In my focus on LINQ to XML, Open XML, and now SharePoint, it’s pretty rare that I have to directly use a SQL database. I only do so maybe once or twice a year, and each time it comes up, I can’t remember where to get the database, and the easiest way to get started. This post is a cheat-sheet for the future - posting this just so that the next time it comes up, I can get going faster.
Add the following two Using statements:
using System.Data.Linq;using System.Data.Linq.Mapping;
Add the following code to Main:
DataContext db = new DataContext(@"C:\Users\ericwhit\Documents\NorthwindDatabase\Northwnd.mdf");Table<Customer> Customers = db.GetTable<Customer>();var query = from cust in Customers where cust.City == "London" select cust;foreach (var cust in query) Console.WriteLine("id = {0}, City = {1}", cust.CustomerID, cust.City);
To install adventure works database,
Download it here.
Install it in a sub folder of my Documents directory.
Add a data connection in Server Explorer.
Zeyad presented this morning on the Open XML SDK at PDC. You can view the video of the talk here – it’s
http://www.microsoft.com/downloads/thankyou.aspx?familyId=06616212-0356-46a0-8da2-eebc53a68034&displayLang=en
Thank you ! Finally I use linq on databese. People need algorithm of doing something that is all !