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是空的。
发布于 2015-07-21 20:41:38
您需要从r中选择,而不是从contactsRow中选择。
https://stackoverflow.com/questions/31549092
复制相似问题