【发布时间】:2019-09-24 15:17:48
【问题描述】:
我有以下代码:
Entity account = service.Retrieve("account", ID, new ColumnSet(true));
string name = (string)account.Attributes["name"];
const string fetchXmlPattern =
@"<fetch mapping='logical' version='1.0'>
<entity name='account'>
<attribute name='maintname' />
<filter>
<condition attribute='maintname' operator='eq' value='{0}' />
</filter>
<link-entity name='contact' from='contactid' to='primarycontactid' link-type='inner'>
<attribute name='accountidname'/>
</link-entity>
</entity>
</fetch>";
string fetchXml = string.Format(fetchXmlPattern, name);
var fetchExpression = new FetchExpression(fetchXml);
EntityCollection response = service.RetrieveMultiple(fetchExpression);
var records = response.Entities;
List<Account> Accounts= new List<Account>();
foreach (var item in records)
{
Account AccountFranchisee = new Account();
AccountFranchisee.ID = (Guid)item.Attributes["accountid"];
AccountFranchisee.Name = (string)item.Attributes["accountidname"];
Accounts.Add(AccountFranchisee);
}
return Accounts;
我在这一行得到一个 Key Not Found 异常:
AccountFranchisee.Name = (string)item.Attributes["accountidname"];
意味着它找不到链接实体中的属性。我尝试在互联网上放置别名,更改模式,更改语法和几种解决方案等...我花了很多时间在这件事上,仍然无法弄清楚哪里出了问题。
如何获得价值?
谢谢!
【问题讨论】:
标签: c# asp.net-mvc fetchxml