I’d like to use the .Join() method in LINQ to perform the following SQL:
select * from Enquiries e, QuoteLines q where e.EnquiryId = q.EnquiryId and e.AccountNum = '123' and q.LineNumber = 'ABC123'
The parameters used for AccountNum and LineNumber will be dynamically passed to the method.
How would I transfer this to use the LINQ .Join() method?
public ActionResult EnquirySearch(string id)
{
var enquiries = new List<Enquiries>();
if(id.Contains(' '))
{
string[] searchArr = id.Split(' ');
// want to do my LINQ here
// this will be split so the first element in the array is the AccountNum
// and the second element in the array is the LineNumber
}
else
{
enquiries = context.Enquiries.Where(x=>x.QuoteRef.Contains(id)
|| x.AccountNum.Contains(id) || x.Owner.Contains(id));
}
return View(enquiries);
}
It’s easier to express a join in an expression query, where it would be something like:
Or you could filter “early” – which would make a difference in LINQ to Objects, but almost certainly not in LINQ to SQL / EF: