【发布时间】:2020-04-21 07:11:44
【问题描述】:
经过一段时间让我的查询在语法上正确,看起来 sdk 有一些限制。我还尝试了一个带有功能的子查询,但它返回了一个 IQuery(i 或其他东西)。有没有办法在 Linq Xrm 查询中实现动态 where 子句
抛出的异常
System.NotSupportedException:方法“Where”不能跟随方法“Select”或不受支持。尝试根据支持的方法编写查询或调用 'AsEnumerable' 或 'ToList' m 调用不受支持的方法之前的方法。
var predicate = PredicateBuilder.New<GetAllResult>(false);
if (query?.ObservationOnStart != null && query?.ObservationOnEnd != null)
{
predicate.And(result =>
result.ObservationEntity.esor_ObservationOn >= query.ObservationOnStart &&
result.ObservationEntity.esor_ObservationOn <= query.ObservationOnEnd);
}
var queryable = from observationEntity in _ctx.esor_ObservationSet
join facilityEntity in _ctx.core_FacilitySet
on observationEntity.esor_Facility.Id equals facilityEntity.Id
orderby observationEntity.esor_ObservationOn
select new GetAllResult {ObservationEntity = observationEntity, FacilityEntity = facilityEntity}
;
// THIS throws exception
queryable.Where(predicate).ToList();
我也尝试过检查变量并使用和 OR 但它也会引发异常
where completedById.Equals(null) || observationEntity.esor_CompletedBy.Id.Equals(completedById)
System.NotSupportedException:“where”条件无效。实体成员正在调用无效的属性或方法
【问题讨论】:
标签: c# linq dynamics-crm xrm