在FetchXML中检索链接实体的属性值

问题描述 投票:0回答:1

我有以下代码:

    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;

我在此行收到未找到密钥异常:

AccountFranchisee.Name = (string)item.Attributes["accountidname"];

表示它找不到链接实体中的属性。我尝试在网络上放置别名,更改模式,更改语法以及几种解决方案,等等。。。

我如何获得价值?

谢谢!

我有以下代码:实体帐户= service.Retrieve(“帐户”,ID,新的ColumnSet(true));字符串名称=(string)account.Attributes [“名称”]; const string fetchXmlPattern = ...

c# asp.net-mvc fetchxml
1个回答
0
投票

accountidname是链接实体的属性。因此,您需要使用Aliased值来检索其值。

© www.soinside.com 2019 - 2024. All rights reserved.