【问题标题】:CRM 2013 service, using linq dynamic queries on the endpointCRM 2013 服务,在端点上使用 linq 动态查询
【发布时间】: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


    【解决方案1】:

    对此我很着急,我发现如果数组中的这些属性之一包含一个空值,则动态 linq 查询将严重失败。因此,如果您想使用这种方法,您需要确保您的数组是完整的,并且所有字段都至少有一个空字符串,因为如果您要查找的字段为空,则查询将失败。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-02
      相关资源
      最近更新 更多