I have the following models with nav propertiers set up in Entity Framework Core:
- CRMLocations (one-to-many) CRMPeoples
- CRMPeoples (one-to-many) CRMEmails
- CRMPeoples (one-to-many) CRMPhones
I have the following working Query:
var iqable = _crmDbContext.CRMPeoples
.Where(p =>
p.Name.ToLower().Contains(query) ||
(from e in p.CRMEmails where e.EmailAddress.ToLower().Contains(query) select e).Any() ||
(from h in p.CRMPhones where h.PhoneNumberNormalized.Contains(query) select h).Any())
.Select(p => new CRMSearchResultDTO()
{
PersonName = p.Name,
LocationName = p.CRMLocations.Name,
});
How can I replace the "(from in where select).Any()" statements to use Linq's lambda syntax? Must result in 1 SQL statement. Can use left outter joins, or nested select.
I got this code by using ReSharper's command "Convert LINQ to method chain"