These days I am playing arround with DLINQ and enjoying quering over SQL SERVER database (DLINQ supports only SQL SERVER opps!). I needed a query to return me all the Categories and their respective Products (I am using Northwind database)




These days I am playing arround with DLINQ and enjoying quering over SQL SERVER database (DLINQ supports only SQL SERVER opps!). I needed a query to return me all the Categories and their respective Products (I am using Northwind

database). Seems, like an easy task and it is :).

First, I thought about using group by so I came up with the following query:

 var query = from c in northwind.Categories
                        join p in northwind.Products
                        on c.CategoryID equals p.CategoryID
                        group p by p.CategoryID into products
                        select new { CategoryID = products.Key, Products = products };


But soon I realized that I need much more information then CategoryID and Products. I needed CategoryName also which was not provided by this query.

I finally realized that by default DLINQ does not use lazy loading. It means that if I fetch the Categories then it will select all the respective products without any effort (manual

effort). So, here is a query which will return all the Categories and their respective Products:

 var q = from c in northwind.Categories
                    select new
                           {
                               CategoryID = c.CategoryID,
                               CategoryName = c.CategoryName,
                               Products = c.Products                                           
                           };


But, now the question is how can I *enable* lazy loading.

If you look at the diagram that is generated when you drag and drop the tables on the designer surface you will note that they don't consists of any foreign keys or relationships. I would

agree that if you show the relationships with the public properties it will confuse the developer since he is assuming the properties to be a mirror image of the database table schema. But,

I think it would have been good idea to show the relationships and collections under a different tab called (Relationships).

If we can see the relationships we can easily select it set the "Delay Loaded" property to *true* which means we are not going to load the child elements.

I guess they are still working on DLINQ and we will see more advance features in the future.