Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CRM 2013服务,在端点上使用linq动态查询_Linq_Linq To Entities_Dynamics Crm 2011_Dynamics Crm 2013 - Fatal编程技术网

CRM 2013服务,在端点上使用linq动态查询

CRM 2013服务,在端点上使用linq动态查询,linq,linq-to-entities,dynamics-crm-2011,dynamics-crm-2013,Linq,Linq To Entities,Dynamics Crm 2011,Dynamics Crm 2013,在crm端点上使用动态查询时遇到问题。有趣的是,如果我在手工制作的数组上应用相同的linq过滤器,查询将正确执行: 这是正在运行的代码的一部分: List<Account> per = new List<Account>(); per.AsQueryable(); per.Add(new Account { LogicalName = "account" }); per.Add(new Account { LogicalName = "account" });

在crm端点上使用动态查询时遇到问题。有趣的是,如果我在手工制作的数组上应用相同的linq过滤器,查询将正确执行:

这是正在运行的代码的一部分:

 List<Account> per = new List<Account>();
 per.AsQueryable();
 per.Add(new Account { LogicalName = "account" });
 per.Add(new Account { LogicalName = "account" });
 per.Add(new Account { LogicalName = "account" });
 per.Add(new Account { LogicalName = "account" });
 per.Add(new Account { LogicalName = "account" });
 per[0]["name"] = "Fourth1";
 per[1]["name"] = "Fourth2";
 per[2]["name"] = "Fourth3e";
 per[3]["name"] = "Fourth4e";
 per[4]["name"] = "Fourth5";
 per[0]["address1_postalcode"] = "Fourth1";
 per[1]["address1_postalcode"] = "Fourth2";
 per[2]["address1_postalcode"] = "Fourth3e";
 per[3]["address1_postalcode"] = "Fourth4e";
 per[4]["address1_postalcode"] = "Fourth5";
 fields.Add("Attributes[\"name\"].ToString().Contains(@0)");
 List<object> paramObjects = new List<object>();

 var where = string.Join(" ", fields.ToArray());
 var toParam = keyPosition.ToArray();
 int queryz = per.AsQueryable().Where(where, toParam).ToList().Count;
List per=新列表();
per.AsQueryable();
per.Add(新帐户{LogicalName=“帐户”});
per.Add(新帐户{LogicalName=“帐户”});
per.Add(新帐户{LogicalName=“帐户”});
per.Add(新帐户{LogicalName=“帐户”});
per.Add(新帐户{LogicalName=“帐户”});
每[0][“名称”]=“第四个1”;
每[1][“名称”]=“第四个2”;
per[2][“name”]=“Fourth3e”;
每[3][“名称”]=“第四个”;
每[4][“名称”]=“第四个5”;
per[0][“address1\u postalcode”]=“Fourth1”;
per[1][“address1\u postalcode”]=“Fourth2”;
per[2][“地址1\u postalcode”]=“第四方”;
每[3][“地址1_postalcode”]=“第四个”;
每[4][“地址1_postalcode”]=“第四个5”;
fields.Add(“Attributes[\“name\”].ToString().Contains(@0)”);
List paramObjects=new List();
var-where=string.Join(“,fields.ToArray());
var toParam=keyPosition.ToArray();
int queryz=per.AsQueryable().Where(Where,toParam.ToList().Count;
直到这里一切都很好,过滤器工作正常,我基本上可以做任何我想做的事情。这是给我带来麻烦的部分:

var query_exists = service.CreateQuery("account");
List<Entity> ent = query_exists.ToList();
int c=  ent.AsQueryable().Where(where, toParam).ToList().Count;
var query_exists=service.CreateQuery(“账户”);
List ent=query_exists.ToList();
int c=ent.AsQueryable().Where(Where,toParam.ToList().Count;
使用与top相同的参数时,我希望使用相同的查询,但如果我尝试将其应用于服务。CreateQuery()时,所有操作都会失败,因为泛型键不存在于字典中。
有人知道手工制作的数组和我正在从端点转换的数组之间是否有任何区别?

这让我非常头疼,我发现如果数组中的某个属性包含一个空值,动态linq查询将严重失败。因此,如果您想使用这种方法,您需要确保您的数组是完整的,并且所有字段都至少有一个空字符串,因为如果您要查找的字段为空,那么查询将失败