【发布时间】:2014-08-21 03:55:36
【问题描述】:
我无法在 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;
直到这里一切都很好,过滤器正在工作,我基本上可以做任何我想做的事情。这是给我带来麻烦的部分:
var query_exists = service.CreateQuery("account");
List<Entity> ent = query_exists.ToList();
int c= ent.AsQueryable().Where(where, toParam).ToList().Count;
使用与 top 相同的参数,我期望相同的查询可以工作,但如果我尝试将其应用于 service.CreateQuery() 一切都会失败,因为泛型密钥不存在于字典中。 有人知道手工数组和我从端点转换的数组有什么区别吗?
【问题讨论】:
标签: linq linq-to-entities dynamics-crm-2011 dynamics-crm-2013