【发布时间】:2021-03-15 12:04:34
【问题描述】:
您好,我尝试像这样在 EF 3.1 上进行查询:
Expression<Func<MedicalResponsibleWard, bool>> predicate = x => x.InstitutionId == request.InstitutionId;
if (request.GroupId != null)
predicate = predicate.AndAlso(x => x.GroupId == request.GroupId);
if (request.Code != null)
predicate = predicate.AndAlso(x => x.Code == request.Code);
if (request.MedicalResponsibleWarName != null)
predicate = predicate.AndAlso(x => x.Properties.Any(m => m.Name.Contains(request.MedicalResponsibleWarName, StringComparison.InvariantCultureIgnoreCase)));
return (await _genericRepository.GetAsync(predicate, query => query.Include(c => c.Properties)))
.OrderBy(g => g.Id).ToList();
但是由于这个谓词导致转换失败
if (request.MedicalResponsibleWarName != null)
predicate = predicate.AndAlso(x => x.Properties.Any(m => m.Name.Contains(request.MedicalResponsibleWarName, StringComparison.InvariantCultureIgnoreCase)));
错误是
The LINQ expression 'DbSet<MedicalResponsibleWardProperty>
.Where(m0 => EF.Property<Nullable<int>>((EntityShaperExpression:
EntityType: MedicalResponsibleWard
ValueBufferExpression:
(ProjectionBindingExpression: EmptyProjectionMember)
IsNullable: False
), "Id") != null && EF.Property<Nullable<int>>((EntityShaperExpression:
EntityType: MedicalResponsibleWard
ValueBufferExpression:
(ProjectionBindingExpression: EmptyProjectionMember)
IsNullable: False
), "Id") == EF.Property<Nullable<int>>(m0, "MedicalResponsibleWardId"))
.Any(m0 => m0.Name.Contains(
value: __request_MedicalResponsibleWarName_1,
comparisonType: InvariantCultureIgnoreCase))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
请问如何解决? 问候
【问题讨论】:
标签: c# postgresql entity-framework asp.net-core