2

尝试使用 linq 在亚音速中进行左连接,但它似乎不起作用,我遇到了一个大错误。

我很确定查询是正确的,因为我已经用对象和 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};

似乎亚音速无法从左连接 linq 查询中生成所需的 SQL。

我在这里做错了吗?有解决办法吗?

更新:我正在使用亚音速 3.0.0.2 这是我尝试使用亚音速左连接时遇到的错误

1[GetAQuote.Post]' cannot be used for parameter of type 'System.Linq.IQueryable方法'System.Linq.IQueryable 1[<>f__AnonymousType22[GetAQuote.Post,System.Collections.Generic.IEnumerable 1[GetAQuote.Quote]]] GroupJoin[Post,Quote,Int32,<>f__AnonymousType22](System.Linq.IQueryable 1[GetAQuote.Post], System.Collections.Generic.IEnumerable1[GetAQuote )的类型'System.Collections.Generic.IEnumerable 1[GetAQuote.Post]'的表达式.Quote], System.Linq.Expressions.Expression 1[System.Func2[GetAQuote.Post,System.Int32]], System.Linq.Expressions.Expression 1[System.Func2[GetAQuote.Quote,System.Int32]], System.Linq.Expressions.Expression 1[System.Func3 [GetAQuote.Post,System.Collections.Generic.IEnumerable 1[GetAQuote.Quote],<>f__AnonymousType22[GetAQuote.Post,System.Collections.Generic.IEnumerable`1[GetAQuote.Quote]]]])'

4

4 回答 4

4

我有一个用于左连接的叉子,我将在接下来的几天内将其拉出 - 给我一个星期,我将推出另一个版本。

于 2009-07-19T06:21:01.413 回答
3

在这里恢复一个老话题,但对于那些稍后搜索的人来说,有一种不同的语法似乎在 SubSonic3 中可以正常工作,用于左外连接。

而不是原始帖子中的 Linq 表达式:

        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};

将其重写为:

        var post = from p in Post.All()
                    from q in Quote.All().Where(x => x.PostID == p.ID).DefaultIfEmpty()
                    where p.ID == id.Value
                    select new {p, q};

希望这可以帮助某人!

于 2011-05-05T17:43:53.940 回答
1

我认为这是一个错误,并且不会得到 Subsonic 的支持。我在这里做其他事情时遇到了同样的问题

于 2009-07-16T11:49:30.573 回答
0

t 似乎仍然没有解决此问题的方法。一个简单的解决方法(虽然很脏)是创建一个处理左连接的视图,并用默认数据填充右侧的空数据,并让 SubSonic 在该视图上进行简单的连接。

我知道这很糟糕,但现在可以解决。由于这个限制,我看不到放弃 SubSonic。我相信它很快就会被修复。

于 2010-01-25T02:32:58.883 回答