我有以下模型,在Entity Framework Core中设置了nav propertiers:
我有以下工作查询:
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,
});
如何替换“(从where where select).Any()”语句来使用Linq的lambda语法?必须导致1个SQL语句。可以使用左外连接或嵌套选择。
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,
});
我使用ReSharper的命令“将LINQ转换为方法链”获得此代码