我正在绑在使用Country2
名称的自定义实体,通过在C#中为Microsoft Dynamics 365 CRM编写插件。我正在以这种方式尝试;
// Create the custom entity.
CreateEntityRequest createrequest = new CreateEntityRequest
{
//Define the entity
Entity = new EntityMetadata
{
SchemaName = "Country2",
DisplayName = new Label("Country2", _languageCode),
DisplayCollectionName = new Label("Countries2", _languageCode),
Description = new Label("An entity to store information about cities.", 1033),
OwnershipType = OwnershipTypes.UserOwned,
IsActivity = false,
},
// Define the primary attribute for the entity
PrimaryAttribute = new StringAttributeMetadata
{
SchemaName = "new_countryname",
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
MaxLength = 100,
FormatName = StringFormatName.Text,
DisplayName = new Label("Country Name", _languageCode),
Description = new Label("The primary attribute for the Country entity.", _languageCode)
}
};
service.Execute(createrequest);
//Entity must be published
// Add few attributes to the custom activity entity.
CreateAttributeRequest fontFamilyAttributeRequest = new CreateAttributeRequest
{
EntityName = "Country2",
Attribute = new StringAttributeMetadata
{
SchemaName = prefix + "fontfamily",
DisplayName = new Label("Font Family", _languageCode),
MaxLength = 100
}
};
CreateAttributeResponse fontFamilyAttributeResponse =
(CreateAttributeResponse)service.Execute(
fontFamilyAttributeRequest);
CreateAttributeRequest fontColorAttributeRequest =
new CreateAttributeRequest
{
EntityName = "Country2",
Attribute = new StringAttributeMetadata
{
SchemaName = prefix + "fontcolor",
DisplayName = new Label("Font Color", _languageCode),
MaxLength = 50
}
};
CreateAttributeResponse fontColorAttributeResponse =
(CreateAttributeResponse)service.Execute(
fontColorAttributeRequest);
CreateAttributeRequest fontSizeAttributeRequest =
new CreateAttributeRequest
{
EntityName = "Country2",
Attribute = new IntegerAttributeMetadata
{
SchemaName = prefix + "fontSize",
DisplayName = new Label("Font Size", _languageCode)
}
};
CreateAttributeResponse fontSizeAttributeResponse =
(CreateAttributeResponse)service.Execute(
fontSizeAttributeRequest);
throw new InvalidPluginExecutionException("The Country custom entity has been created.");
在上面的代码中,我尝试首先制作new entity
,然后尝试设置PrimaryAttribute
,最后CreateAttributeRequest
。
,但提示了;
的错误您不能以与当前事务上已经设置的不同隔离级别启动交易。 这里有什么错吗?
不确定没有自定义前缀的实体可以创建实体。现在您的实体是" country2",我将其更改为" new_country2"您的代码非常紧密地遵循在线提供的示例https://msdn.microsoft.com/en-us/library/gg509014.aspx
尝试将其切换到在线上,以查看该文章中是否使用相同名称创建实体/属性。