最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

c# - Dynamic Linq GroupJoin Issue - Stack Overflow

matteradmin8PV0评论

I have a big question about the use of conditions in group joins using Dynamic Linq Query syntax.

I have the following code, which I am using to generate a left join code.

result = result.AsQueryable().GroupJoin(entitiesQuerySecundary.AsQueryable(), "REventID", "EventID", $"new(outer as p, inner as s)");
result = result.SelectMany("s.DefaultIfEmpty()", $"new({string.Join(", ", selectedPropertyNames)})").Distinct();

Here in the first result I create the group join with a single code making the comparison of the input and output parameter.

My question is there a way to use 2 conditions? for example REventID = EventID plus RStatus = StatusID.

I have a big question about the use of conditions in group joins using Dynamic Linq Query syntax.

I have the following code, which I am using to generate a left join code.

result = result.AsQueryable().GroupJoin(entitiesQuerySecundary.AsQueryable(), "REventID", "EventID", $"new(outer as p, inner as s)");
result = result.SelectMany("s.DefaultIfEmpty()", $"new({string.Join(", ", selectedPropertyNames)})").Distinct();

Here in the first result I create the group join with a single code making the comparison of the input and output parameter.

My question is there a way to use 2 conditions? for example REventID = EventID plus RStatus = StatusID.

Share Improve this question asked Nov 16, 2024 at 7:13 Sergio MarchantSergio Marchant 1 1
  • I never use dynamic ling, but new(REventID, RStatus), new(EventID, Status)? – Gert Arnold Commented Nov 16, 2024 at 16:43
Add a comment  | 

1 Answer 1

Reset to default 0

You are doing a group join of the result table with entitiesQuerySecundary and assigning it back to the result, which will create a problem.

If you want to group join "table1" with "table2". You can try -

var result = table1.AsQueryable().GroupJoin(
    table2.AsQueryable(),
    "new (REventID, RStatus)",  
    "new (EventID, StatusID)",  
    "new (outer as table1, inner as table2)"
);

This should return rows from table1 and corresponding rows from table2 where both keys match.

Post a comment

comment list (0)

  1. No comments so far