I have created a query expressions which retrieves all order products associated with an order.
Here is my current query expression:
var query = new QueryExpression("salesorderdetail");
query.ColumnSet = new ColumnSet(new string[] { "salesorderdetailid", "productid", "new_event", "new_inventory", "productdescription" });
query.Criteria.AddCondition("salesorderid", ConditionOperator.Equal, combinedEntity.Id);
query.Distinct = true;
EntityCollection retrieved = context.OrganizationService.RetrieveMultiple(query);
The problem is that I only want to retrieve data with a unique productid.
Is this possible using QueryExpression? Can anyone show me?
Many thanks.
I am not 100% sure what you are asking, however there is a trick I like to use that may help when writing query expressions:
While this is not “code” per se, it usually contains some good hints on how to write it. Also, there is the option of using a Fetch XML query in your code as well.
Use FetchXML to Construct a Query
http://msdn.microsoft.com/en-us/library/gg328117.aspx
If you just need the distinct set of ProductIds contained within the sales order, couldn't just remove the other columns from the ColumnSet? Like so:
query.ColumnSet = new ColumnSet(new string[] { "productid" });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.