简体   繁体   中英

C# Linq Join Into statement editor error

var joinedTables =  from tableRow in filteredTable.AsEnumerable()
                    join contactsRow in contacts.AsEnumerable()
                    on tableRow.Field<double>("Opportunity: Store Number") equals contactsRow.Field<double>("National Store .")
                    into lj
                    from r in lj.DefaultIfEmpty()
                    select resultTable.LoadDataRow(new object[]
                    {
                        tableRow.Field<double>("Opportunity: Store Number"),
                        tableRow.Field<DateTime>("Target Circuit Completion (FOC)"),
                        tableRow.Field<string>("Vendor Name"),
                        contactsRow.Field<string>("Contacts - ACM - Email")
                    }, false);

I am trying to do a left-outer-join on two tables using LinQ using this answer . However when I try to add fields from contactsRow into the object array argument of the .LoadDataRow() function, the editor says 'contactsRow' does not exist in the current context. How is my code different from the answer in my link? I have been really trying to learn LineQ to avoid crazy-nested loops but this has me stumped. More code here .

EDIT:

var joinedTables =  from tableRow in filteredTable.AsEnumerable()
                            join contactsRow in contacts.AsEnumerable()
                            on tableRow.Field<double>("Opportunity: Store Number") equals contactsRow.Field<double>("National Store .")
                            into lj
                            from r in lj.DefaultIfEmpty()
                            select resultTable.LoadDataRow(new object[]
                            {
                                tableRow.Field<double>("Opportunity: Store Number"),
                                tableRow.Field<DateTime>("Target Circuit Completion (FOC)"),
                                tableRow.Field<string>("Vendor Name"),
                                r.Field<string>("Contacts - ACM - Email"),
                                r.Field<string>("OO - Ops Mgr Name"),
                                r.Field<string>("Contacts - Area Sup / BC - Email"),
                                r.Field<string>("Contacts - OTP - Email"),
                                r.Field<string>("OTM Email Address")
                            }, false);
        return resultTable;

I changed the code from resultTable to r in my select statement as suggested. The code compiles now but resultTable is empty.

您需要从r中选择而不是从contactRow中选择。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM