[英]How can I query Dynamics 365 CRM as the logged in user in an ASP.NET MVC site authenticated with AAD?
[英]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帳戶,存儲在通用List集合中並返回它。
如果要創建一個帳戶,請使用此代碼。
Entity account = new Entity("account");
account["name"] = "test account";
Guid _accountId = _service.Create(account);
閱讀更多有關清楚解釋的樣本的信息,也有關_service
初始化的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.