3

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

Required member 'LogicalName' missing for field 'Target'

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

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

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;
    }
}
4

1 回答 1

5

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

account = new Entity("your_entity_name");

或者

account = new Entity();
account.LogicalName = "your_entity_name";
于 2014-10-06T11:53:58.857 回答