【问题标题】:Required member 'LogicalName' missing for field 'Target'字段“目标”缺少必需的成员“逻辑名称”
【发布时间】:2014-10-02 22:05:19
【问题描述】:

我正在使用Microsoft XRM SDK 以编程方式添加实体。但是,每次我运行 .Create() 命令时,都会出现以下错误:

Required member 'LogicalName' missing for field 'Target'

第一次使用该服务,我们公司的类似资源很少,所以不知道这个错误是什么意思或如何调查/解决它。

下面是我创建的用于处理 XRM 通信的类。我在构造函数中实例化每个连接属性。然后,在这种情况下,请致电CreateAgency(AgentTransmission agt)。在.Create(account) 方法调用的CreateAgency() 方法中引发了异常。

class DynamicsCommunication
{
    private Uri OrganizationUri = new Uri("http://devhildy03/xRMDRMu01/XRMServices/2011/Organization.svc");
    private ClientCredentials credentials;
    private OrganizationServiceProxy servicePoxy;
    private Guid accountId;
    private Entity account;

    public DynamicsCommunication()
    {
        credentials = new ClientCredentials();
        credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
        servicePoxy = new OrganizationServiceProxy(OrganizationUri, null, credentials, null);
        accountId = Guid.Empty;
    }

    public string UpdateDynamics(AgentTransmission agt)
    {
        switch (DeterminAction(agt))
        {
            case DynamicsAction.Create:
                return CreateAgency(agt);
            case DynamicsAction.Update:
                return UpdateAgency(agt);
            default:
                return string.Empty;
        }
    }

    private string CreateAgency(AgentTransmission agt)
    {
        try
        {
            //Exception is thrown after this command
            accountId = servicePoxy.Create(CreateAccount(agt));

            if (accountId != Guid.Empty)
            {
                return string.Empty;
            }
            else
            {
                return "error creating agency";
            }
        }
        catch (ODataException oEx)
        {
            string s = oEx.Message;
            throw;
        }
        catch (Exception ex)
        {
            string s = ex.Message;
            throw;
        }
    }

    private Entity CreateAccount(AgentTransmission agt)
    {
        account = new Entity();
        account.Attributes.Add("LogicalName", "something");
        account.Attributes.Add("name", agt.AgencyName);
        account.Attributes.Add("telephone1", agt.BusinessPhone.Replace("(","").Replace(")", "").Replace("-", ""));
        account.Attributes.Add("address1_line1", agt.MailingStreet1);
        account.Attributes.Add("address1_city", agt.MailingCity);
        account.Attributes.Add("address1_postalcode", agt.MailingZip);
        account.Attributes.Add("neu_address1stateprovince", 1); //1 for Mailing
        account.Attributes.Add("neu_channelid", LookupChannelId(agt.Channel));
        account.Attributes.Add("neu_appointementstatus", "279660000");
        account.Attributes.Add("customertypecode", LookupCustomerCode(agt.RelationshipType));
        account.Attributes.Add("neu_taxid", UnobfuscateRef(agt.ReferenceNumber));

        return account;
    }
}

【问题讨论】:

    标签: c# odata wcf-data-services xrm


    【解决方案1】:

    在 Entity 对象的 LogicalName 属性上设置 CRM 实体的名称,而不是将其添加到属性集合中

    account = new Entity("your_entity_name");
    

    account = new Entity();
    account.LogicalName = "your_entity_name";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 2014-05-14
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 2022-11-24
      相关资源
      最近更新 更多