gpt4 book ai didi

c# - 字段 'LogicalName' 缺少必需的成员 'Target'

转载 作者:行者123 更新时间:2023-11-30 14:55:04 24 4
gpt4 key购买 nike

我正在使用 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;
}
}

最佳答案

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

account = new Entity("your_entity_name");

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

关于c# - 字段 'LogicalName' 缺少必需的成员 'Target',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26170376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com