5

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?

CleverPatrick
  • 9,261
  • 5
  • 63
  • 86

1 Answers1

8

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.

nemesv
  • 138,284
  • 16
  • 416
  • 359