使用 Microsoft.CrmSdk 程序集在 Dynamics 365 for Customer Engagement(版本 9)中生成实体,我发现来自 CrmServiceClient 的 GetEntityMetadata 方法无法从实体中获取最新信息。
这里的代码向您展示:
using (var svc = new CrmServiceClient(strConn))
{
EntityMetadata em = svc.GetEntityMetadata(PREFIX + TABLE_NAME_D, EntityFilters.Attributes);
if (em == null)
{
Console.WriteLine($"Create entity [{PREFIX + TABLE_NAME_D}]");
CreateEntityRequest createRequest = new CreateEntityRequest
{
Entity = new EntityMetadata
{
SchemaName = PREFIX + TABLE_NAME_D,
LogicalName = PREFIX + TABLE_NAME_D,
DisplayName = new Label(TABLE_LABEL, 1036),
DisplayCollectionName = new Label(TABLE_LABEL_P, 1036),
OwnershipType = OwnershipTypes.UserOwned,
},
PrimaryAttribute = new StringAttributeMetadata
{
SchemaName = PREFIX + "name",
MaxLength = 30,
FormatName = StringFormatName.Text,
DisplayName = new Label("Residence", 1036),
}
};
CreateEntityResponse resp = (CreateEntityResponse)svc.Execute(createRequest);
em = svc.GetEntityMetadata(PREFIX + TABLE_NAME_D, EntityFilters.All);
// At this point, em is null!!!
}
}
收到 createResponse 后,实体在 Dynamics 中创建良好,但之后调用的 GetEntityMetadata 仍然为空。如果我等待几秒钟再打一个电话,现在响应是正确的。但这太可怕了!有没有办法“强制”刷新响应?谢谢。