尝试执行WHERE IN:无效的"where"条件.实体成员正在调用无效的属性或方法 [英] Trying to execute a WHERE IN: Invalid 'where' condition. An entity member is invoking an invalid property or method

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

问题描述

我正在尝试获取在先前列表中找到其AccountID的案件的列表.

I'm trying to get a list of cases whose AccountID is found in a previous list.

该错误发生在以下内容的最后一行:

The error occurs on the last line of the following:

// Gets the list of permissions for the current contact
var perms = ServiceContext.GetCaseAccessByContact(Contact).Cast<Adx_caseaccess>();

// Get the list of account IDs from the permissions list
var customerIDs = perms.Select(p => p.adx_accountid).Distinct();

// Get the list of cases that belong to any account whose ID is in the `customerID` list
var openCases = (from c in ServiceContext.IncidentSet where customerIDs.Contains(c.AccountId) select c).ToList();

我不确定错误所指的是无效属性".代码编译后,我在运行时得到了错误.

I'm not sure what the "invalid property" is the error is talking about. The code compiles, I just get the error at runtime.

推荐答案

问题是 CRM Linq提供程序.它不支持Linq-to-objects提供程序提供的所有可用选项.在这种情况下,CRM不支持Enumerable.Contains()方法.

The problem is the CRM Linq Provider. It doesn't support all of the available options that the Linq-to-objects provider offers. In this case, the CRM does not support the Enumerable.Contains() method.

位置: 子句的左侧必须是属性名称,并且 子句的右侧必须是一个值.您不能设置左侧 到一个常数.子句的两面都不能为常数. 支持字符串功能,包含 StartsWith EndsWith 等于.

where: The left side of the clause must be an attribute name and the right side of the clause must be a value. You cannot set the left side to a constant. Both the sides of the clause cannot be constants. Supports the String functions Contains, StartsWith, EndsWith, and Equals.

您可以通过以下两种方法之一解决此问题:

You can work around this in one of two ways:

  1. 重做查询以使用更自然的联接.
  2. 如果无法进行联接,则可以使用Dynamic Linq在customerIDs中的每个项目上生成OR子句的列表.此功能类似于Enumerable.Contains.
  1. Rework your query to use a more natural join.
  2. If a join is not possible, you can use Dynamic Linq to generate a list of OR clauses on each item in customerIDs. This would function similarly to Enumerable.Contains.

查看我对这个问题的答案或接受的答案如何获得是今天的所有生日吗?" 提供两种单独的方法来实现这一目标.

See my answer or the accepted answer to the question "How to get all the birthdays of today?" for two separate ways to accomplish this.

这篇关于尝试执行WHERE IN:无效的"where"条件.实体成员正在调用无效的属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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