使用C#代码从DYNAMICS 365 crm检索/获取记录 [英] Retrieve/fetch records from DYNAMICS 365 crm using C# code
问题描述
-
问题1:
Problem 1:
我是MICROSOFT DYNAMICS CRM 365的新手。我的CRM很少有一些表,例如(帐户,Customer)。我想从表帐户中获取所有数据。
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.
下面是我的连接示例代码:(不确定这是否正确,但是得到我已连接到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)
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");
}
我需要在按钮单击事件中检索所有数据。
输出应为:从ABC选择*的结果
;
I need all data to be retrieved on button click event .
Output should be: result of "select * from ABC"
;
- 问题2:
请建议如何使用给定的列名来获取记录。
输出应为: select * from ABC where ColumnName = test
;
if possible please suggest how to fetch records using given column name.
Output should be: result of "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);
}
//具有单个参数的功能(以oganizationservice作为参数)
//Function with single parameter (oganizationservice as a parameter)
//这将从Microsoft Dynamics CRM获取表/实体名称,如ACCOUNT,CONTACT
//This will fetch Table/Entity Name Like ACCOUNT,CONTACT from Microsoft Dynamics CRM
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
}
这篇关于使用C#代码从DYNAMICS 365 crm检索/获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!