问题描述
尝试使用 linq 在 subsonic 中进行左连接,但似乎不起作用,我遇到了一个大错误.
Trying to do a left join in subsonic using linq but it doesn't seem to work, I get a big error.
我很确定查询是正确的,因为我已经用对象和 Linq2Sql 做过几次了.
I'm pretty sure the query is correct as I've done it a few times with objects and Linq2Sql.
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};
似乎 subsonic 无法从左连接 linq 查询生成所需的 SQL.
It just seems subsonic isn't able to generate the required SQL from left join linq queries.
我在这里做错了吗?有解决办法吗?
Am I doing something wrong here? Is there a work around?
更新:我使用的是 subsonic 3.0.0.2,这是我尝试使用 subsonic 进行左连接时出现的错误
Update: I'm using subsonic 3.0.0.2 here is the error I get when I try a left join with subsonic
'System.Collections.Generic.IEnumerable1[GetAQuote.Post]' 类型的表达式不能用于方法类型 'System.Linq.IQueryable
1[GetAQuote.Post]' 的参数'System.Linq.IQueryable1[<>f__AnonymousType2
2[GetAQuote.Post,System.Collections.Generic.IEnumerable1[GetAQuote.Quote]]] GroupJoin[Post,Quote,Int32,<>f__AnonymousType2
2](System.Linq.IQueryable1[GetAQuote.Post], System.Collections.Generic.IEnumerable
1[GetAQuote.Quote], System.Linq.Expressions.Expression1[System.Func
2[GetAQuote.Post,System.Int32]], System.Linq.Expressions.Expression1[System.Func
2[GetAQuote].Quote,System.Int32]], System.Linq.Expressions.Expression1[System.Func
3[GetAQuote.Post,System.Collections.Generic.IEnumerable1[GetAQuote.Quote],<>f__AnonymousType2
2[GetAQuote.Post,System.Collections.Generic.IEnumerable`1[GetAQuote.Quote]]]])'
Expression of type 'System.Collections.Generic.IEnumerable1[GetAQuote.Post]' cannot be used for parameter of type 'System.Linq.IQueryable
1[GetAQuote.Post]' of method 'System.Linq.IQueryable1[<>f__AnonymousType2
2[GetAQuote.Post,System.Collections.Generic.IEnumerable1[GetAQuote.Quote]]] GroupJoin[Post,Quote,Int32,<>f__AnonymousType2
2](System.Linq.IQueryable1[GetAQuote.Post], System.Collections.Generic.IEnumerable
1[GetAQuote.Quote], System.Linq.Expressions.Expression1[System.Func
2[GetAQuote.Post,System.Int32]], System.Linq.Expressions.Expression1[System.Func
2[GetAQuote.Quote,System.Int32]], System.Linq.Expressions.Expression1[System.Func
3[GetAQuote.Post,System.Collections.Generic.IEnumerable1[GetAQuote.Quote],<>f__AnonymousType2
2[GetAQuote.Post,System.Collections.Generic.IEnumerable`1[GetAQuote.Quote]]]])'
推荐答案
我有一个用于 left join 的 fork,我将在接下来的几天内使用它 - 给我一周时间,我将推出另一个版本.
I have a fork for left join that I'll be pulling in the next few days - gimme a week and I'll push another release with this.
这篇关于Subsonic 3.0 左连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!