2010-03-27 103 views
1

我试图做亚音速3使用linq左连接,但它似乎不工作,我得到一个大错误。左亚音速加入3

 var post = from p in Post.All() 
        join q in Quote.All() on p.ID equals q.PostID into pq 
        where p.ID == id.Value 
        from qt in pq.DefaultIfEmpty() 
        select new {p, qt}; 

我使用亚音速3,最新的Git版本来自Rob,但我得到一个错误,见下文,当我尝试左连接。 我已经搜索,但我没有找到任何解决方案。

任何人都可以向我解释为什么错误以及如何解决它? 由于

Expression of type 'System.Collections.Generic.IEnumerable1[GetAQuote.Post]' cannot be used for parameter of type 'System.Linq.IQueryable1[GetAQuote.Post]' of method 'System.Linq.IQueryable1[<>f__AnonymousType221[GetAQuote.Post], System.Collections.Generic.IEnumerable1%5BGetAQuote.Quote%5D, System.Linq.Expressions.Expression1[System.Func2%5BGetAQuote.Post,System.Int32%5D%5D, System.Linq.Expressions.Expression1[System.Func2%5BGetAQuote.Quote,System.Int32%5D%5D, System.Linq.Expressions.Expression1[System.Func3%5BGetAQuote.Post,System.Collections.Generic.IEnumerable1[GetAQuote.Quote],<>f__AnonymousType22%5BGetAQuote.Post,System.Collections.Generic.IEnumerable 1%5BGetAQuote.Quote%5D%5D%5D%5D“> GetAQuote.Post,System.Collections.Generic.IEnumerable1 [GetAQuote.Quote]]]群组加入[邮政,报价单,的Int32,<> f__AnonymousType22'`

回答

0

解决左连接在Subsonic3你只需要设置.AsEnumerable()方法在你的LINQ查询。

试试这个

categories.AsEnumerable()或products.AsEnumerable()

+1

当我尝试这是我过去的错误,但结果数据库活动是从两个表中选择所有,显然留下所有加入逻辑在核心完成。这是不对的,是吗? – 2011-04-25 22:03:26

+0

@凯利,我一直在研究亚音速3的核心,是的,这似乎是发生了什么。 '.AsEnumerable'显然等同于'.ToList',因为它从数据库中获取绝对的一切。此外,Subsonic似乎没有任何代码来处理嵌套查询 – Earlz 2011-06-27 22:28:47