BLToolkit:如何使用 LINQ 获取主从结果集?
以下是列表关联的示例用法,取自 BLToolkit 文档< /a>:
from p in db.Product
select new
{
p.OrderDetails.Count,
p.ProductName
};
是否
class Product
{
[PrimaryKey, Identity]
public int ProductID;
public string ProductName;
[Association(ThisKey="ProductID", OtherKey="ProductID")]
public List<OrderDetail> OrderDetails;
}
可以获取包含每个产品的订单详细信息的产品列表,如下所示:
from p in db.Product
select new
{
Details = p.OrderDetails,
p.ProductName
};
上面的代码抛出 LinqException 并显示以下消息:
找不到 'System.Collections.Generic.List`1[[OrderDetail] 的转换器,TestProject,版本=1.0.0.0,文化=中性,PublicKeyToken=null]]'类型。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然我没有使用过 BLToolkit,但您可能会尝试使用您定义的类,而不是依赖于匿名类型。
也就是说,您可以定义一个名为
MyOrder
的类,该类具有String ProductName
和List属性。 OrderDetails
,然后将 linq 查询更改为以下内容:我不能保证这会起作用,但可能值得一试(除非有人发布更明确的内容)。
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 propertiesString ProductName
andList<OrderDetail> OrderDetails
, and then change your linq query to something like:I can't guarantee that this would work, but it's probably worth a shot (unless someone posts something more definitive).
使用普通的 linq to sql 提供程序就可以正常工作。对于 BLToolkit Linq 提供程序,我不知道。
Using the normal linq to sql provider this would work fine. With the BLToolkit Linq provider I don't know.