Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AllowHtml attribute on EntityFramework class

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?

like image 323
CleverPatrick Avatar asked Apr 11 '12 18:04

CleverPatrick


1 Answers

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.

like image 122
nemesv Avatar answered Sep 28 '22 15:09

nemesv