.Contains
阅读后,我发现在使用SDK Linq 提供程序查询 CRM 2011 时无法使用该方法。这是一个问题,因为我需要查询属于从我的应用程序传递的 Guid 集合的记录。经过更多调查后,我发现了 LinqKit 和 Predicate Builder;伟大的!在查询中使用单个实体集,谓词可以正常工作:
var visits = Context.Crm_scheduled_visitSet.AsExpandable().Where(predicate);
我遇到的问题是,当我扩展查询以包含与另一个实体集的连接时,当我包含谓词时,我无法运行查询。这是我的查询,没有运行正常的谓词,但我需要在Crm_scheduled_visitSet
Guid 的集合上过滤:
var scores = Context.Crm_scheduled_visitSet
.Join(Context.crm_business_risk_scoreSet, v => v.Crm_scheduled_visitId.Value, s => s.crm_business_risk_score_id.Id, (v, s) => new
{
OrgID = v.Crm_client_id.Id,
VisitStartdate = object.Equals(null, v.crm_actual_start_date) ? new DateTime() : v.crm_actual_start_date.Value,
SectionId = s.crm_business_risk_section_id.Id,
RisLevelId = s.crm_business_risk_level_id.Id,
RiskRatingId = s.crm_business_risk_rating_id.Id
});
我需要做的但这不运行:
var scores = base.Context.Crm_scheduled_visitSet.AsExpandable().Where(predicate)
.Join(base.Context.crm_business_risk_scoreSet, v => v.Crm_scheduled_visitId.Value, s => s.crm_business_risk_score_id.Id, (v, s) => new
{
OrgID = v.Crm_client_id.Id,
VisitStartdate = object.Equals(null, v.crm_actual_start_date) ? new DateTime() : v.crm_actual_start_date.Value,
SectionId = s.crm_business_risk_section_id.Id,
RisLevelId = s.crm_business_risk_level_id.Id,
RiskRatingId = s.crm_business_risk_rating_id.Id
});