我有一个注册了Update,Order,Post Operation的插件。在插件中,我在salesorderdetail上执行了一个检索。我遇到的问题是有3个产品组成订单,但我从检索操作返回5行。我在测试过程中多次添加和删除了同一产品,我不确定这是不是导致问题的原因。我在想,在从订单中删除产品后,它可能会设置一个标志并在之后被删除,但我没有看到状态代码或状态代码作为属性。为什么会返回太多行?
这是我的代码......
// Set the properties of the QueryExpression object.
orderDetailQuery.EntityName = "salesorderdetail";
orderDetailQuery.ColumnSet = orderDetailColumnSet;
EntityCollection salesOrderDetail = service.RetrieveMultiple(orderDetailQuery);
orderProductQuery.EntityName = "product";
orderProductQuery.ColumnSet = orderProductColumnSet;
foreach (var orderDetail in salesOrderDetail.Entities)
{
if(orderDetail.Attributes.Contains("productid"))
{
productGuid = ((EntityReference)orderDetail["productid"]).Id;
Entity product = service.Retrieve("product", productGuid, orderProductColumnSet);
}
}
谢谢你的帮助!!
答案 0 :(得分:1)
您发布的代码不会显示您针对特定Order
进行过滤。
我希望在系统中检索该类型的所有实体。
要假设您使用QueryByAttribute
进行过滤,请按以下方式添加过滤器:
var query = new QueryByAttribute();
query.EntityName = "salesorderdetail";
query.AddAttributeValue("orderid", orderId);//orderId is the Id of the parent Order
orderDetailQuery.EntityName = "salesorderdetail";
orderDetailQuery.ColumnSet = orderDetailColumnSet;
var results = service.RetrieveMultiple(query);
这样您就可以将查询限制为仅针对给定订单的产品。
答案 1 :(得分:0)
我不确定您的过滤是否已实施。以下是关于如何查询 SalesOrderDetail 实体的实例,获取 fieldName1 和 fieldName2 字段的值的说明,前提是它是使用guid orderId 链接到订单。
QueryExpression query = new QueryExpression
{
EntityName = "salesorderdetail",
ColumnSet = new ColumnSet("fieldName1", "fieldName2"),
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression
{
AttributeName = "orderid",
Operator = ConditionOperator.Equal,
Values = { orderId }
}
}
}
};