在欧盟或Concat的类型不能与层次构建 [英] Types in Union or Concat cannot be constructed with hierarchy
问题描述
我试图运行非常类似于以下的查询:
I am trying to run a query very similar to the following:
(from bs in DataContext.TblBookShelf
join b in DataContext.Book on bs.BookID equals b.BookID
where bs.BookShelfID == bookShelfID
select new BookItem
{
Categories = String.Join("<br/>", b.BookCategories.Select(x => x.Name).DefaultIfEmpty().ToArray()),
Name = b.Name,
ISBN = b.ISBN,
BookType = "Shelf"
}).Union(from bs in DataContext.TblBookShelf
join bi in DataContext.TblBookInventory on bs.BookID equals bi.BookID
select new BookItem
{
Categories = String.Join("<br/>", bi.BookCategories.Select(x => x.Name).DefaultIfEmpty().ToArray()),
Name = bi.Name,
ISBN = bi.ISBN,
BookType = "Inventory"
});
我收到了在联盟或Concat的类型不能与层次结构建造的说法执行后,我需要是能够得到的类别,以显示与每本书的列表。如果任何人都可以在一个可能的解决方案提供一些线索,这将大大AP preciated。
I am receiving "Types in Union or Concat cannot be constructed with hierarchy" after the statement executes, I need to to be able to get a list of categories to display with each book. If anyone could shed some light on a possible solution, it would be greatly appreciated.
推荐答案
现在的问题是,你是选择在查询的子序列,你的工会(即 b.BookCategories
)。这是一个LINQ 2 SQL限制。它没有这种转换为SQL(因为这将是很难做到的,所以我想球队选择不支持这一点)。
The problem is that you are selecting a sub-sequence in the queries that you union (i.e. b.BookCategories
). This is a LINQ 2 SQL limitation. It fails to translate this to SQL (because it would be very hard to do, so I guess the team chose not to support this).
摆脱子序列选择的。大概在这种情况下,最简单的解决方法是执行联邦客户端。执行两个服务器端的查询和合并的结果。
Get rid of the sub-sequence select. Probably the easiest fix in this case is to execute the union client-side. Execute two server-side queries and merge the results.
性能将是可怕的,因为如果反正序列子选择。您可能希望就如何以有效的方式获取与L2S树研究。
Performance will be horrible anyway because if the sequence sub-select. You might want to research on how to fetch trees with L2S in an efficient way.
这篇关于在欧盟或Concat的类型不能与层次构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!