我是Dynamics CRM中的新成员,我想创建一个控制台应用程序,可以为帐户实体创建新记录,并可以显示来自Dynamics CRM在线帐户实体的所有帐户名称的列表。如何使用控制台应用程序从Dynamics CRM Online中检索数据?
这是我的代码:
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查询=新QueryExpression {实体名称= “帐户”,ColumnSet =新ColumnSet(新的String [] { “名”}) }; EntityCollection account = service.RetrieveMultiple(query); 是否这样? – Dev
是的,就像那样。 –