【问题标题】:How to retrive data from Dynamics CRM Online using console application?如何使用控制台应用程序从 Dynamics CRM Online 检索数据?
【发布时间】:2016-09-12 18:29:25
【问题描述】:

我是 Dynamics CRM 的新手,我想创建一个控制台应用程序,它可以为帐户实体创建新记录,并可以显示来自 Dynamics CRM 在线帐户实体的所有帐户名称的列表。

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int choice;
            CrmServiceClient crmConn = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRM"].ConnectionString);
            IOrganizationService crmService = crmConn.OrganizationServiceProxy;

            Entity acc = new Entity("account");
            String account_name;
            Console.WriteLine("Press 1 to Create a new account or Press 2 to view list of available accounts.");
            choice = Convert.ToInt32(Console.ReadLine());
            switch (choice)
            {
                case 1:
                    Console.WriteLine("Enter Name of Account to Create ?");
                    account_name = Console.ReadLine();
                    acc["name"] = account_name;
                    crmService.Create(acc);
                    Console.WriteLine("*****An account with name {0} is created successfully*****", account_name);
                    Console.WriteLine();
                    Console.WriteLine("Press any key to exit..");
                    Console.ReadKey();
                    break;
                case 2:
                    //code to display list of all account names in CRM.
                    Console.ReadKey();
                    break;
                default:
                    Console.WriteLine("Wrong input...");
                    Console.ReadKey();
                    break;

            }
        }

    }
}

【问题讨论】:

  • 如果你想检索数据你需要做一个QueryExpression
  • QueryExpression query = new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet(new string[] { "name" }) }; EntityCollection account = service.RetrieveMultiple(query);像这样?
  • 是的,就像那样。
  • 谢谢@GuidoPreite,我做到了。
  • 如果已解决,请添加答案。如果你能阅读this community discussion关于紧急乞讨的信息,那就太好了,谢谢。

标签: dynamics-crm microsoft-dynamics dynamics-crm-online


【解决方案1】:

这是我的答案

Inside Case 2:我使用了以下代码:

QueryExpression query = new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet(new string[] { "name" }) };
EntityCollection account = crmService.RetrieveMultiple(query);
string name = "";
foreach (var count in account.Entities)
{
    name = count.GetAttributeValue<string>("name");
    Console.WriteLine(name);
}
Console.ReadKey();

【讨论】:

    【解决方案2】:

    对于案例 2,我最好采用使用 FetchXML 的方法。转到高级查找并获取您的过滤条件,然后下载 xml 文件。

    然后将 fetchxml 合并到您的代码中并像这样检索数据

    var objCollection = crmService.RetrieveMultiple(new FetchExpression(fetchXMLString));

    希望对你有帮助

    【讨论】:

    • FetchXML 有 5000 条记录的限制,但我的客户有 5000 多条记录。无论如何,现在工作已经完成。感谢您的回答@Manish
    猜你喜欢
    • 1970-01-01
    • 2013-06-21
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    相关资源
    最近更新 更多