是否可以在 CRM 中动态加入多个字段?
我的意思是在 SQL 中是这样的
select field1, field2, ..., fieldN
from ServiceAppointment
inner join bh_product
on bh_product.bh_contract = ServiceAppointment.bh_product.bh_contract
and bh_product.serviceid = ServiceAppointment.serviceid
我正在尝试使用 queryexpression 提出上述问题,但我没有得到我想要的行为,而且我最终得到的记录比预期的要多。如果我事先知道第 2 个字段的值,我可以这样做,但是在运行时我不知道什么,并且查询必须加入 2 个字段。我的实际代码如下,减去我想不出的部分。
这行不通...我只希望有 2 条记录,但我得到了数百条记录...
var leContact = new LinkEntity(ServiceAppointment.EntityLogicalName, ActivityParty.EntityLogicalName, "activityid", "activityid", JoinOperator.Inner);
leContact.LinkCriteria = new FilterExpression();
leContact.LinkCriteria.AddCondition("partyid", ConditionOperator.Equal, contactId);
queryExpression.LinkEntities.Add(leContact);
result = GetServiceActivityList(queryExpression);
var leService = new LinkEntity(ServiceAppointment.EntityLogicalName, BrightHorizons.Shared.CRM.Interface.Service.EntityLogicalName, "serviceid", "serviceid", JoinOperator.Inner);
queryExpression.LinkEntities.Add(leService);
result = GetServiceActivityList(queryExpression);
// THIS IS THE PROBLEM
var leProduct = new LinkEntity(ServiceAppointment.EntityLogicalName, bh_product.EntityLogicalName, "bh_contract", "bh_contract", JoinOperator.Inner);
var leProduct2 = new LinkEntity(ServiceAppointment.EntityLogicalName, bh_product.EntityLogicalName, "serviceid", "bh_service", JoinOperator.Inner);
queryExpression.LinkEntities.Add(leProduct2);
queryExpression.LinkEntities.Add(leProduct);
result = GetServiceActivityList(queryExpression);
//THIS ALSO DOESNT WORK
var leProduct = new LinkEntity(ServiceAppointment.EntityLogicalName, bh_product.EntityLogicalName, "bh_contract", "bh_contract", JoinOperator.Inner);
leProduct.AddLink(bh_product.EntityLogicalName, "bh_service", "bh_service", JoinOperator.Inner);
queryExpression.LinkEntities.Add(leProduct);
result = GetServiceActivityList(queryExpression);
我究竟做错了什么?