如何使用 asp.net 在 dynamics crm 中创建帐户?

how to create Account in dynamics crm using asp.net?

public List<AccountEntityModels> RetriveRecord()
{           
  using (OrganizationService service = new OrganizationService("MyConnectionString"))               
  {               
    QueryExpression query = new QueryExpression
    {                    
      EntityName = "account",
      ColumnSet = new ColumnSet("name")
    };
    List<AccountEntityModels> info = new List<AccountEntityModels>();
    EntityCollection accountRecord = service.RetrieveMultiple(query);

    if (accountRecord != null && accountRecord.Entities.Count > 0)                    
    {                   
      AccountEntityModels accountModel;

      for (int i = 0; i < accountRecord.Entities.Count; i++)
      {                  
        accountModel = new AccountEntityModels();
        if (accountRecord[i].Contains("name") && accountRecord[i]["name"] != null)
          accountModel.AccountName = accountRecord[i]["name"].ToString();

        info.Add(accountModel);
      }
    }
    return info;
  }
}

以上代码用于检索所有 CRM 帐户,存储在通用列表集合中并返回。

如果您想创建一个帐户,请使用此代码。

Entity account = new Entity("account");
account["name"] = "test account";
Guid _accountId = _service.Create(account);

Read more 示例解释清楚,也关于 _service 初始化。