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



我是新来的LINQ,所以如果我问错了请道歉。我想使用帐户GUID和LINQ检索Dynamics CRM中的帐户号码。却找不到。下面的代码段给出了指定的cast无效的异常

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

什么是accountID ?GuidNullable<Guid>

try下面的代码片段:

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"));

尝试如下:

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();

相关内容

  • 没有找到相关文章

最新更新