Search code examples
c#.netlinqlinq-to-sqlbltoolkit

BLToolkit: how to get master-detail result set using LINQ?


Here is an example usage of list associations taken from BLToolkit documentation:

from p in db.Product
select new
{
  p.OrderDetails.Count,
  p.ProductName
};

where

class Product
{
  [PrimaryKey, Identity]
  public int ProductID;

  public string ProductName;

  [Association(ThisKey="ProductID",  OtherKey="ProductID")]
  public List<OrderDetail> OrderDetails;
}

Is it possible to get list of products with order details for each product like this:

from p in db.Product
select new
{
  Details = p.OrderDetails,
  p.ProductName
};

The code above throws LinqException with the following message:

Cannot find converter for the 'System.Collections.Generic.List`1[[OrderDetail, TestProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' type.


Solution

  • Using the normal linq to sql provider this would work fine. With the BLToolkit Linq provider I don't know.