簡體   English   中英

C#Linq Join Into語句編輯器錯誤

[英]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);

我正在嘗試使用此答案使用LinQ在兩個表上進行左外聯接。 但是,當我嘗試將contactsRow中的字段添加到.LoadDataRow()函數的對象數組參數中時,編輯器說“ contactsRow”在當前上下文中不存在。 我的代碼與鏈接中的答案有何不同? 我一直在嘗試學習LineQ,以避免出現瘋狂的循環,但這讓我很困惑。 更多代碼在這里

編輯:

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;

我按照建議在select語句中將代碼從resultTable更改為r。 代碼現在可以編譯,但是resultTable為空。

您需要從r中選擇而不是從contactRow中選擇。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM