Query Expressions in C# for MS Dynamics

Ankaprasad
Posted by Ankaprasad under C# category on | Points: 40 | Views : 158
Retrieve single record
Entity order = _service.Retrieve("salesorder", new Guid(orderId), new ColumnSet("ordernumber"));


Query with Contains Operator

  string value = "%" + productName + "%";
QueryExpression query = new QueryExpression("product");
query.Criteria.AddCondition("name", ConditionOperator.Like, value);
query.ColumnSet = new ColumnSet("name", "productnumber");
EntityCollection ECProducts = _service.RetrieveMultiple(query);


Condition

(A_logicalName AND B_LogicalName) OR (B_LogicalName AND C_LogicalName)

FilterExpression filter = new FilterExpression(LogicalOperator.Or);

FilterExpression filter1 = new FilterExpression(LogicalOperator.And);
filter1.Conditions.Add(new ConditionExpression("A_LogicalName", ConditionOperator.Equal, id1));
filter1.Conditions.Add(new ConditionExpression("B_LogicalName", ConditionOperator.Equal, id2));

FilterExpression filter2 = new FilterExpression(LogicalOperator.And);
filter2.Conditions.Add(new ConditionExpression("B_LogicalName", ConditionOperator.Equal, id2));
filter2.Conditions.Add(new ConditionExpression("C_LogicalName", ConditionOperator.Equal, id3));

filter.AddFilter(filter1);
filter.AddFilter(filter2);

query.Criteria = filter;

Comments or Responses

Login to post response