0
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.

1
  • 2
    The code in that answer wouldn't work either, I believe. Basically you want r.Field instead of contactsRow.Field, as far as I can tell. Commented Jul 21, 2015 at 20:38

1 Answer 1

1

You need to select from r not from contactsRow.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.