AllowHtml attribute in EntityFramework class

Is there another way to set the [AllowHtml] attribute on a property of a class automatically generated by EntityFramework? I hate changing auto-generated files because every time I make changes to a model, my changes are lost.

But there is no other obvious way to set [AllowHtml] for a specific property, except by using an attribute. Is there a non-attributive way to do this?

+5
source share
1 answer

You can use MetadataTypeAttribute to specify the attributes of the generated code in an associated (friendly) class. Thus, you put your attributes in a separate class that will not be executed when the code is regenerated:

[MetadataType(typeof(YourEntityMetadata))]
public partial class YourEntityClass
{            
}   

public class YourEntityMetadata
{
    [AllowHtml]
    public string YourPropertyWithHtml { get; set; }
}

Property names in metadata must match the object names of your object.

+8
source

All Articles