如何使用asp.net在Dynamics CRM中创建帐户?

时间:2018-08-08 04:24:43

标签: c# dynamics-crm dynamics-crm-2015

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

1 个答案:

答案 0 :(得分:0)

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

如果要创建帐户,请使用此代码。

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

Read more中的示例也进行了清楚的解释,还涉及_service初始化。