admin管理员组文章数量:1389783
I need a LINQ query that performs an outer join recursively that uses a list of datatables for the left side of the join on clause, another list for the datatables to use for the right clause and a list of common key columns to join on. I've managed to get this so that the first join clause joins as expected but subsequent joins stack the data rather than outer joining it.
This is the code from ChatGPT:
var result = onLeftJoinTables.Select((leftTable, index) =>
{
var rightTable = onRightJoinTables[index];
var keyColumn = columnKeys[index];
return from leftRow in leftTable.AsEnumerable()
join rightRow in rightTable.AsEnumerable()
on leftRow[keyColumn] equals rightRow[keyColumn] into t
from rightRow in t.DefaultIfEmpty()
select leftRow["RS_ID"];
})
.SelectMany(x => x)
.ToList();
I've selected a single column to try and narrow down the problem rather than select a "merge rows" method but it still returns the same number of rows as the stacked data.
These are the tables and ID column I want to join:
[Applicant, Authorisation, APL_ID]
[Authorisation, Decision, DCN_ID]
[Authorisation, Use, USE_ID]
Could someone please help me as I've been working on this for hours.
本文标签: cLINQ query for recursively joining tablesStack Overflow
版权声明:本文标题:c# - LINQ query for recursively joining tables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744717571a2621495.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论