samin samin - 1 month ago 10
ASP.NET (C#) Question

how do I get multiple resultset in Linq c#?

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();
}


The emailobj return null, how do I get multiple resultset?

Thanks,

Answer
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();
Comments