简体   繁体   English

使用 C# 代码从 DYNAMICS 365 crm 检索/获取记录

[英]Retrieve/fetch records from DYNAMICS 365 crm using C# code

  • Problem 1:问题1:

    I am new to MICROSOFT DYNAMICS CRM 365. I have few tables with my CRM like(Account,Customer).I want to fetch all data from table account.我是 MICROSOFT DYNAMICS CRM 365 的新手。我的 CRM 表很少,例如(帐户,客户)。我想从表帐户中获取所有数据。

Below is my sample code for connection:(not sure this is correct or not but getting output message that i am connected to CRM)以下是我的连接示例代码:(不确定这是否正确,但收到我已连接到 CRM 的输出消息)

public void ConnectToMSCRM(string UserName, string Password, string SoapOrgServiceUri)  
    {  
        try  
        {  
            ClientCredentials credentials = new ClientCredentials();  
            credentials.UserName.UserName = UserName;  
            credentials.UserName.Password = Password;  
            Uri serviceUri = new Uri(SoapOrgServiceUri);  
            OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);  
            proxy.EnableProxyTypes();  
            _services = (IOrganizationService)proxy;  
            Response.Write("Connected to CRM \n");  
}  

I need all data to be retrieved on button click event .我需要在按钮单击事件上检索所有数据。
Output should be: result of "select * from ABC" ;输出应该是: "select * from ABC"

  • Problem 2:问题2:

if possible please suggest how to fetch records using given column name.如果可能,请建议如何使用给定的列名获取记录。
Output should be: result of "select * from ABC where ColumnName="test" ;输出应该是: "select * from ABC where ColumnName="test"

Fetching all entities list into List将所有实体列表提取到列表中

    var allEntities = **GetEntities(_service);**
    foreach (var Entity in allEntities)
    {
        ddlEntityName.Items.Add(Entity.LogicalName);
    }

//Function with single parameter (oganizationservice as a parameter) //单参数函数(oganizationservice作为参数)

//This will fetch Table/Entity Name Like ACCOUNT,CONTACT from Microsoft Dynamics CRM //这将从 Microsoft Dynamics CRM 中获取表/实体名称,如 ACCOUNT、CONTACT

public Microsoft.Xrm.Sdk.Metadata.EntityMetadata[] GetEntities(IOrganizationService organizationService)
    {
        Dictionary<string, string> attributesData = new Dictionary<string, string>();
        RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest();
        RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse();
        metaDataRequest.EntityFilters = EntityFilters.Entity;

        XmlDictionaryReaderQuotas myReaderQuotas = new XmlDictionaryReaderQuotas();
        myReaderQuotas.MaxNameTableCharCount = 2147483647;

        // Execute the request.

        metaDataResponse = (RetrieveAllEntitiesResponse)organizationService.Execute(metaDataRequest);

        var entities = metaDataResponse.EntityMetadata;

        return entities.OrderBy(x => x.LogicalName).ToArray();//to arrange in ascending order
    }

What about query expression?查询表达式呢?

This is your query :这是您的查询:

Select * from ABC where ColumnName="test";

And this is the QueryExpression :这是QueryExpression

QueryExpression query = new QueryExpression()
{
    EntityName = Contact.EntityLogicalName,
    ColumnSet = new ColumnSet("address1_telephone1"),
};

to excute the query, this is how :执行查询,这是如何:

DataCollection<Entity> entityCollection = _services.RetrieveMultiple(query).Entities;

// Display the results.
foreach (Contact entity in entityCollection)
{
    Console.WriteLine("my test: {0}", entity.address1_telephone1);
}

Regards问候

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在带有C#插件的Dynamics CRM组织中使用Dynamics 365 Web API检索所有记录(超过5000页和/或一页以上)? - How can I retrieve all records (more than 5000 and/or more than 1 page) with the Dynamics 365 Web API in a Dynamics CRM organization with a C# plugin? 如何使用MS动态CRM 2016中的c#检索部分,选项卡? - How can I retrieve sections, tabs by using c# from MS dynamics CRM 2016? Microsoft Dynamics 365 CRM 身份验证的示例代码,然后重定向到 C# 控制台应用程序 - sample code for Microsoft Dynamics 365 CRM authentication and then redirect to C# console application 如何通过Dynamics CRM 365内部部署中的插件在CRM Online中检索记录 - How to retrieve records in CRM Online through plugin in Dynamics CRM 365 On-Premise CRM v9-使用C#代码从CRM实体中删除基于ID的记录 - CRM v9 - Delete records based on ID from CRM Entity using C# Code 读取数据集合<Entity>来自使用 C# 的 Dynamics CRM - Reading DataCollection<Entity> from Dynamics CRM using C# 使用C#从CRM 365中的Lookup动态获取价值 - Get Value Dynamically from Lookup in CRM 365 using C# 使用C#合并Dynamics CRM中的联系人 - Merge Contacts in Dynamics CRM using C# 如何 go 关于它:从 Microsoft Dynamics 365 CRM 同步/导出帐户数据并在第 3 方 web 应用程序中显示? 使用 WS 和 ASP.NET MVC/C# - How to go about it: sync/export data for Accounts from Microsoft Dynamics 365 CRM and show it in a 3rd party web app? Using WS and ASP.NET MVC/C# Dynamics 365 (CRM) 9.1 版在线 C# 代码错误:实体 ID 必须与属性包中设置的值相同 - Dynamics 365 (CRM) Version 9.1 online C# code Error: Entity Id must be the same as the value set in property bag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM