上的EntityFramework类AllowHtml属性 [英] AllowHtml attribute on EntityFramework class
问题描述
有没有设置[AllowHtml]属性上是由的EntityFramework自动生成的类的属性不同的方式?我讨厌改变自动生成的文件,因为每次我做一个模型更改,我的变化迷路。
Is there a different way of setting the [AllowHtml] attribute on a property of a class that is being auto-generated by EntityFramework? I hate changing the autogenerated files because every time I make a change to the model, my changes get lost.
但是,对于比通过使用属性之外的特定属性设置[AllowHtml]没有其他明显的方式。是否有这样做的一个非属性的方式?
But there is no other obvious way for setting [AllowHtml] for a specific property other than by using the attribute. Is there a non-attribute way of doing it?
推荐答案
您可以使用 MetadataTypeAttribute 一>指定在相关(好友)类生成的code属性。所以,你放在一个单独的类属性的,不会与code再生成下列程序进行:
You can use the MetadataTypeAttribute to specify attributes for the generated code in an associated (buddy) class. So you put your attributes in a separate class which won't be effected with the code re-generation:
[MetadataType(typeof(YourEntityMetadata))]
public partial class YourEntityClass
{
}
public class YourEntityMetadata
{
[AllowHtml]
public string YourPropertyWithHtml { get; set; }
}
在元数据类中的属性名称应与实体属性的名称。
The property names in the Metadata class should match your entity property names.
这篇关于上的EntityFramework类AllowHtml属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!