Ho i seguenti modelli con i correttori nav configurati in Entity Framework Core:
Ho la seguente query di lavoro:
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,
});
Come posso sostituire le istruzioni "(from in where select) .Any ()" per usare la sintassi lambda di Linq? Deve risultare in 1 istruzione SQL. È possibile utilizzare i join esterni a sinistra o selezionare nidificati.
var iqable = _crmDbContext.CRMPeoples
.Where(p =>
p.Name.ToLower().Contains(query) ||
p.CRMEmails.Where(e => e.EmailAddress.ToLower().Contains(query)).Any() ||
p.CRMPhones.Where(h => h.PhoneNumberNormalized.Contains(query)).Any())
.Select(p => new CRMSearchResultDTO()
{
PersonName = p.Name,
LocationName = p.CRMLocations.Name,
});
Ho ottenuto questo codice usando il comando di ReSharper "Converti LINQ in catena di metodi"