2014-10-02 170 views
2

我正在使用Microsoft XRM SDK以編程方式添加實體。然而,每次我運行一個.Create()命令我碰到下面的錯誤:在使用本服務以及類似的資源,我們公司是稀缺必填字段'LogicalName'缺少字段'Target'

Required member 'LogicalName' missing for field 'Target' 

第一次,所以不知道這是什麼錯誤意味着或如何調查/解決問題。

下面是我創建的用於處理XRM通信的類。我實例化了construtor中的每個連接屬性。然後,在這種情況下,請致電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; 
    } 
} 

回答

4

設置在實體對象的LogicalName財產CRM實體的名稱,而不是將它添加到屬性收集

account = new Entity("your_entity_name"); 

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