【发布时间】:2022-11-04 19:46:44
【问题描述】:
我正在尝试在 Dynamics 365 租户(版本 9.2.22101.170)和 Microsoft.CrmSdk 版本 9.0.2.46 中查询产品相关信息。大多数情况下,我对通过产品编号查询产品以检索价格信息感兴趣,但稍后我会介绍更多参数。以下是我尝试过的众多方法之一(我知道我暂时只预测名称,最终我需要价格信息等):
var cols = new ColumnSet(new String[] { "name" });
QueryByAttribute query = new QueryByAttribute("product");
query.ColumnSet = cols;
query.Attributes.AddRange("productnumber");
query.Values.AddRange("100002");
var results = service.RetrieveMultiple(query);
if (results != null)
{
var entities = results.Entities.ToList();
if (entities != null)
{
var productEnt = (Product)entities.FirstOrDefault();
Console.WriteLine(productEnt.Name);
}
}
这是在 RetrieveMultiple 调用中返回的错误消息:
在 MetadataCache 中找不到名称 = 'product' 且名称映射 = 'Logical' 的实体。 MetadataCacheDetails:ProviderType=Dynamic,StandardCache=True,IsLoadedInStagedContext=False,Timestamp=8343791,MinActiveRowVersion=8343791
调用任何其他方法时返回相同的消息。很明显,问题不在于查询或返回的列,而是“产品”。
果然,我是用下面的方法来获取实体名称列表的,“Product”这个词没有出现。我认为这解释了错误消息。
public static EntityMetadata[] GetEntities(IOrganizationService organizationService) { Dictionary<string, string> attributesData = new Dictionary<string, string>(); RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest(); RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse(); metaDataRequest.EntityFilters = EntityFilters.Entity; // Execute the request. metaDataResponse = (RetrieveAllEntitiesResponse)organizationService.Execute(metaDataRequest); var entities = metaDataResponse.EntityMetadata; return entities; }这是权限问题吗?我需要在查询之前做一些额外的加载吗?如何在 Dynamics 365 租户中查询产品/定价相关信息?
我尝试在网上搜索相关信息,但令我惊讶的是几乎找不到与产品相关的任何内容。
【问题讨论】:
标签: c# sdk dynamics-crm crm dynamics-365