Monday, January 14, 2008

DeKlarit and LinQ (to DataSets)

This is going to be just a short post about how to use DeKlarit's business framework with LinQ.
For this sample I used the well-known Northwind database. So it's pretty simple: create your DeKlarit model, rebuild the project so the business framework gets created and add a new project to the solution. In my case it's just a simple Console application which it's Main method has the following code:

OrdersDataAdapter adapter = new OrdersDataAdapter();
   OrdersDataSet ds = new OrdersDataSet();


   var orders = from OrdersDataSet.OrdersRow order in ds.Orders
                      where order.ShipCountry == "USA"
                      select order;

(var order in orders)
         Console.WriteLine(string.Format("{0}: {1}-{2}",order.CustomerID, order.ShipCity, order.ShipCountry));

Keep in mind that OrdersDataAdapter and OrdersDataSet are the ones from the business framework so you'll need to add a reference to it and add the correct using statement.

And that's it...

No comments: