最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Dynamic Linq GroupJoin Issue - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论