[英]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"
;
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.