使用Dynamic Linq和后期绑定的crm 2015实体

时间:2015-09-16 11:33:23

标签: linq dynamic-linq late-binding dynamics-crm-2015

我想使用Dynamic Linq对crm 2015进行简单查询。 该实体是 new_entity ,并且有一个字符串字段 new_field 。我希望所有new_entity记录都包含 new_field!= null 并且在提供的值列表中。

List<string> possibleValues = new List<string> { "value1", "value2", "value3", "value4" };

string stringQuery = ????;

var result = (from e in organizationServiceContext.CreateQuery("new_entity")
                      .Where(stringQuery)
                      select e).ToList();

我使用后期绑定实体,因此 CreateQuery 将返回IQueryable<Entity>而不是IQueryable<new_entity>。如何使用可能值列表过滤 new_field 来创建stringQuery谓词?

1 个答案:

答案 0 :(得分:2)

使用类似的东西:

.Where(ne => ne.GetAttributeValue<string>("new_field") == "my value")