无效的CRM 2011 LINQ查询:“无效的'where'条件.实体成员正在调用无效的属性或方法. [英] Invalid CRM 2011 LINQ Query: "Invalid 'where' condition. An entity member is invoking an invalid property or method."

查看:51
本文介绍了无效的CRM 2011 LINQ查询:“无效的'where'条件.实体成员正在调用无效的属性或方法.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行此查询以检索特定实体类型的审核项目

I am trying to execute this query to retrieve Audit items for specific entity types

public List<Audit> GetAuditChangesSince(DateTime since, string entityType)
{
    return (from a in OrgContext.CreateQuery<Audit>()
        where
            a.ObjectId != null && a.ObjectId.LogicalName == entityType &&
            a.CreatedOn > since
        select a).ToList();
}

a.ObjectId!= null&& a.ObjectId.LogicalName == entityType& 子句引起了问题.我知道.Equals()可能会引起问题(因此==),并且LINQ Provider存在以下限制:

The a.ObjectId != null && a.ObjectId.LogicalName == entityType && clause is causing problems. I know .Equals() may cause problems (hence ==) and there are these limitations to the LINQ Provider:

子句的左侧必须是属性名称,子句的右侧必须是值

左侧是属性,右侧是常数. .ObjectId.LogicalName是引起此问题的原因吗?

The left side is a property and the right side is a constant. Is the .ObjectId.LogicalName causing the problem?

推荐答案

因为审计实体没有为与特定记录相关的实体的逻辑名称/类型代码提供基本属性,所以您最好在这里可以做的就是链接到您希望为其找到审计记录的一个或多个实体,而无需检索所有记录.

Because the Audit entity doesn't provide an ground-level attribute for the logical name/type code of the entity a particular record is related to, the best you can do here is to link to the entity (or entities) you wish to locate audit records for -- that is without retrieving all the records.

针对这种情况的通用技术是,您可以使用半废话条件链接到相关实体,例如检查主键是否为null.对于您而言,仅链接就足够了.

A general technique for scenarios like this is that you can link to an related entity with a semi-nonsense condition like checking that the primary key is not null. For your case, just the link should be enough.

用于提取与联系人相关联的审核记录的示例:

An example for pulling audit records tied to a contact:

from a in OrgContext.CreateQuery<Audit>()
join c in ContactSet on a.ObjectId.Id equals c.ContactId
where a.ObjectId != null && a.CreatedOn > since
select a

这篇关于无效的CRM 2011 LINQ查询:“无效的'where'条件.实体成员正在调用无效的属性或方法.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆