Wednesday, January 30, 2008

LinQ with DeKlarit's BussinesObjects Addin

I recently showed how to use LinQ to query the BusinessFramework's DataSets. Now using the same model (good old Northwind) I'll show you (in case you haven't figured it out yet) how to query the business objects's collections created by DeKlarit's BusinessObjects Addin.

So let's say you have your orders and you want to get all of them:

           OrdersCollection orders = new OrdersCollection();


And now you want to "query" around for say orders shipped to Brazil (love the beaches), so you'll have to write your linQ query as follows:

            var query = from Orders o in orders
where o.ShipCountry == "Brazil"
select o;

And then just printout whatever you want from the orders:

            foreach (var order in query)
Console.WriteLine(string.Format("Shipped on {0} to {1} @ {2},{3}",order.ShippedDate, order.CustomersCompanyName, order.ShipCity,order.ShipCountry ));
Easy uh?

No comments: