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