Using Dynamic Linq with late bound crm 2015 entities

dynamic-linq dynamics-crm-2015 late-binding linq

Question

I want to make a simple query using Dynamic Linq against crm 2015. The entity is new_entity and has a string field new_field. I want all the new_entity records that have new_field != null and are in a list of provided values.

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();

I'm using late bound entities so CreateQuery will return an IQueryable<Entity> not IQueryable<new_entity>. How do I create the stringQuery predicate in order to filter new_field with the list of possible values?

1
1
9/16/2015 11:33:22 AM

Popular Answer

Use something like this:

.Where(ne => ne.GetAttributeValue<string>("new_field") == "my value")
2
9/16/2015 12:14:44 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow