我如何在Linq c#中获得多个结果集
本文关键字:结果 Linq | 更新日期: 2023-09-27 18:15:50
var compobj = (from a in _db.FO_BA where a.BACode == vbacode select a);
foreach (var a in compobj)
{
companycode = a.CompanyCode.ToString();
}
var emailobj = (from b in _db.EmailSentError where b.CompanyCode == companycode select b);
foreach(var b in emailobj)
{
emails = b.Emails.ToString();
}
emailobj返回null,我如何获得多个结果集?
谢谢,
var companycodeList= _db.FO_BA.Where(a=>a.BACode == vbacode)
.Select(x=>x.CompanyCode.ToString()).ToList();
var emailsList = _db.EmailSentError.Where(x=>companycodeList.Contains(x.CompanyCode))
.Select(y=>y.Emails.ToString()).ToList();
如果你想获得多个电子邮件字符串,那么你可以尝试在LINQ中加入
var emailList = (from a in _db.FO_BA
join b in _db.EmailSentError
on a.CompanyCode equals b.CompanyCode
where a.BACode == vbacode select b.Emails)