0

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.

yallie
  • 2,200
  • 1
  • 28
  • 26

2 Answers2

1

While I haven't used the BLToolkit, you might try to use a class you define rather than relying on an anonymous type.

That is, you could define a class called MyOrder that has properties String ProductName and List<OrderDetail> OrderDetails, and then change your linq query to something like:

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

I can't guarantee that this would work, but it's probably worth a shot (unless someone posts something more definitive).

Kirkaiya
  • 1,145
  • 11
  • 14
  • Thanks for the suggestion. Unfortunately, your code raises the same error. LINQ expression parser doesn't care whether it's normal class or anonymous compiler-generated class used in **select** clause, both of them work well in the first example. – yallie Feb 02 '11 at 11:13
0

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

Magnus
  • 45,362
  • 8
  • 80
  • 118
  • Thanks for your reply. Could you please suggest what SQL query would be generated for this expression by normal LINQ to SQL provider? – yallie Feb 02 '11 at 11:00
  • The query you have written should work fine in Linq2Sql. For BLToolkit, check out: http://groups.google.com/group/bltoolkit/browse_thread/thread/85c00c8d80072e5c "This feature is not supported yet" – Magnus Feb 02 '11 at 12:21
  • Thanks a lot! That's the answer I was looking for: not supported yet. – yallie Feb 03 '11 at 08:39