[英]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.