如何使用LINQ和联接重设CRM Guid?
我们正在使用CRM 2011。我们的合同中有实体对产品的引用,每个产品都有实体对主题的引用。给定合同Guid,我需要检索主题Guid 我是LINQ的初学者,但我编写了:如何使用LINQ和联接重设CRM Guid?,linq,dynamics-crm-2011,Linq,Dynamics Crm 2011,我们正在使用CRM 2011。我们的合同中有实体对产品的引用,每个产品都有实体对主题的引用。给定合同Guid,我需要检索主题Guid 我是LINQ的初学者,但我编写了: var subject = from s in context.SubjectSet join product in context.ProductSet on s
var subject = from s in context.SubjectSet
join product in context.ProductSet
on s.Id equals product.SubjectId.Id
join contract in context.ContractSet
on product.Id equals contract.ce_ProductId.Id
where contract.Id == gContractId
select s;
foreach (var s in subject)
{
newReportableAction.ce_SupergroupRegarding =
new EntityReference(Xrm.Subject.EntityLogicalName, new Guid(s.Id.ToString()));
}
这会引发一个错误:
AttributeFrom和AttributeTo必须同时指定或同时指定。你不能只通过其中一个。属性from:,属性to:ce\u ProductId
这个错误是什么意思?如何获取Guid 更新: 我尝试将查询分成几个部分,以查看错误是从何处产生的,因此:
var query = from product in context.ProductSet
join contract in context.ContractSet
on product.Id equals contract.ce_ProductId.Id
这使得:
join子句中某个表达式的类型不正确。调用“join”时类型推断失败
感谢所有帮助您的人…我认为您不能在Linq语句中使用实体的.Id属性。请尝试以下方法:
var query = from product in context.ProductSet
join contract in context.ContractSet
on product.ProductId equals contract.ce_ProductId.Id
注意
product.ProductId
而不是product.Id
我从来没有想到过这一点-谢谢你的回答,这让我省去了很多挫折,因为错误消息似乎与解决方案无关