AllowHtml attribute on EntityFramework class

♀尐吖头ヾ 提交于 2019-12-07 05:02:43

问题


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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/10112094/allowhtml-attribute-on-entityframework-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!