0

我正在使用链接实体加入两个实体:

LinkEntity pricelevelentity = new LinkEntity();
pricelevelentity.JoinOperator = JoinOperator.Inner;
pricelevelentity.LinkFromEntityName = "product";
pricelevelentity.LinkFromAttributeName = "productid";

pricelevelentity.LinkToEntityName = "productpricelevel";
pricelevelentity.LinkToAttributeName = "productid";
query.LinkEntities.Add(pricelevelentity);

以上是在 ProductId 属性上加入 Product 和 ProductPriceLevel。我还想在 ProductPriceLevel.DefaultUomId 上添加到联接 Product.uomid

我怎样才能做到这一点?

4

2 回答 2

2

如果您尝试为链接/连接的实体返回一列以便能够在客户端执行额外的过滤,那么您应该使用LinkEntity一个Column属性,例如:

new QueryExpression("product")
{
    ColumnSet = new ColumnSet("oumid"),
    LinkEntities =
    {
        new LinkEntity("product", "productpricelevel", "productid", "productid", JoinOperator.Inner)
        {
            Columns = new ColumnSet("defaultuomid")
        }
    }
};
于 2013-04-19T11:13:32.607 回答
1

不确定詹姆斯的答案是如何被标记为答案的,但您不能使用链接实体加入多个列。您可以使用 James 的答案返回两个值,并在客户端执行连接,但 CRM 不支持这种类型的连接:

Select * FROM A INNER JOIN B ON A.OneId = B.OneId AND A.TwoId = B.TwoId

如果您知道产品的 UomId 的值,则可以将其添加到 where 子句中:

var qe = new QueryExpression("product");
var productPriceLevel = new LinkEntity("product", "productpricelevel", "productid", "productid", JoinOperator.Inner);
qe.LinkEntities = productPriceLevel;
productPriceLevel.LinkCriteria.AddCondition("defaultuomid", ConditionOperator.Equal, product.UomId);

这实际上看起来像这样:

Select * FROM A INNER JOIN B ON A.OneId = B.OneId AND B.TwoId = 10 -- the Value of whatever the single A.TwoId value is you're looking for.
于 2013-04-19T13:07:20.103 回答