开发者

Why can't I use a where clause on both tables in a LINQ Group Join?

开发者 https://www.devze.com 2023-03-11 06:04 出处:网络
Here\'s what I want to do: Dim queryX = From m In db.Master Where m.Field = value Group Join d In db.Detail

Here's what I want to do:

Dim queryX = From m In db.Master
             Where m.Field = value
             Group Join d In db.Detail
             On m.Id Equals d.MasterId Into Group
             Where d.Field = value

In English, I want to join the master and detail tables, specifying conditions on each. But this causes the following compiler error:

"Name 'd' is either not declared or not in the current scope."

It works if I put this same condition in functional form:

Group Join d In db.Detail.Where(Function(x) x.Field = value)

but I think this is more typing, harder to understand, and introduces that irritating dummy variable. I really would prefer to use the query comprehensi开发者_开发技巧on syntax. Is there a way to accomplish this?


Are you sure you need a group join here and not just a join like this

try

Dim queryX = From m In db.Master
             Where m.Field = value
             Join d In db.Detail
             On m.Id Equals d.MasterId 
             Where d.Field = value;

?

0

精彩评论

暂无评论...
验证码 换一张
取 消