使用Dynamics CRM中的帐户GUID检索帐号

时间:2015-07-30 08:52:00

标签: c# linq dynamics-crm-2011 guid

我是LINQ的新手,所以如果我提出错误的问题,请道歉。我想使用帐户GUID和LINQ在Dynamics CRM中检索帐号。但无法找到。我已经关注了代码段,但是我发现指定的广告素材无效

 accountID = (Guid)contact["parentcustomerid"];
 var account = from a in context.CreateQuery("account")
 where a.GetAttributeValue<Guid?>("accountid") == accountID
 select new {accountNumber = a["accountnumber"] };

2 个答案:

答案 0 :(得分:0)

什么是accountIDGuidNullable<Guid>

尝试以下代码段:

accountID = (Guid)contact["parentcustomerid"];
var account = from a in context.CreateQuery("account")
where a.GetAttributeValue<Guid>("accountid") == accountID
select new {accountNumber = a.GetAttributeValue<int>("accountnumber") };

您可以使用Query Expression。它非常易于使用:

QueryExpression queryExpression = new QueryExpression("account");
queryExpression.ColumnSet = new ColumnSet("accountnumber");
queryExpression.Criteria.AddCondition("accountid", ConditionOperator.Equal, accountID);

_service.Retrieve("account", accountID, new ColumnSet("accountnumber"));

答案 1 :(得分:0)

尝试以下内容:

var accountID = contact.GetAttributeValue<EntityReference>("parentcustomerid").Id;

var accountnumber = (from a in context.CreateQuery("account")
 where a.GetAttributeValue<Guid>("accountid") == accountID
 select a.GetAttributeValue<string>("accountnumber")).FirstOrDefault();