C# 使用Dynamics CRM中的帐户GUID检索帐户号
我是LINQ的新手,所以如果我问错了问题,请道歉。我想使用帐户GUID和LINQ检索Dynamics CRM中的帐户号。但是找不到。我有以下代码段,但给出了一个异常,指定的强制转换无效C# 使用Dynamics CRM中的帐户GUID检索帐户号,c#,linq,dynamics-crm-2011,guid,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 = (Guid)contact["parentcustomerid"];
var account = from a in context.CreateQuery("account")
where a.GetAttributeValue<Guid?>("accountid") == accountID
select new {accountNumber = a["accountnumber"] };
accountID=(Guid)联系人[“parentcustomerid”];
var account=来自上下文中的一个。CreateQuery(“account”)
其中a.GetAttributeValue(“accountid”)==accountid
选择新的{accountNumber=a[“accountNumber”]};
什么是accountID
<代码>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") };
或
什么是accountID
<代码>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") };
或
尝试以下方法:
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();
var accountID=contact.GetAttributeValue(“parentcustomerid”).Id;
var accountnumber=(来自context.CreateQuery(“account”)中的
其中a.GetAttributeValue(“accountid”)==accountid
选择一个.GetAttributeValue(“accountnumber”).FirstOrDefault();
尝试以下方法:
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();
var accountID=contact.GetAttributeValue(“parentcustomerid”).Id;
var accountnumber=(来自context.CreateQuery(“account”)中的
其中a.GetAttributeValue(“accountid”)==accountid
选择一个.GetAttributeValue(“accountnumber”).FirstOrDefault();
service.retrieve返回“Microsoft.Xrm.SDK.Entity”,当我调试时,它只在属性中显示id。你能帮忙吗this@MohsinAli您是否指定了new ColumnSet(“accountnumber”)
yes,这里是,Entity account=service.Retrieve(account.LogicalName,accountID,new ColumnSet(“accountnumber”)@MohsinAli如果accountnumber
为空,则它将不在属性中。我确信它是空的。我甚至尝试了以下方法:ColumnSet col1=new ColumnSet();col1.Columns.Add(“accountnumber”);但是没有luckservice.retrieve返回“Microsoft.Xrm.SDK.Entity”,当我调试时,它只在属性中显示id。你能帮忙吗this@MohsinAli您是否指定了new ColumnSet(“accountnumber”)
yes,这里是,Entity account=service.Retrieve(account.LogicalName,accountID,new ColumnSet(“accountnumber”)@MohsinAli如果accountnumber
为空,则它将不在属性中。我确信它是空的。我甚至尝试了以下方法:ColumnSet col1=new ColumnSet();col1.Columns.Add(“accountnumber”);但是没有运气