I've got a class that was generated for me by the Entity Framework:
Models/EF.tt/Product.cs
public partial class X
{
public int Name { get; set; }
...
}
I don't want to modify it because it's managed by the EF editor and it will wipe out my modifications any time I regenerate it, so I'm putting code into a separate file. Because the classes are declared as partial I can do useful things... what I haven't been able to figure out is how to use DataAnnotations for the properties.
Models/EF.custom.cs
public partial class X
{
[Display(Name = "My Name")]
public int Name { get; set; }
...
}
which fails... what is the proper way to do this?
partial classes can work by convention. For example consider this convention. // file main function SomeObject() { for (var i = 0, ii = SomeObject. Partial.
DataAnnotations namespace includes the following validator attributes: Range – Enables you to validate whether the value of a property falls between a specified range of values. RegularExpression – Enables you to validate whether the value of a property matches a specified regular expression pattern.
Your going to want to use a metadatatype:
http://ryanhayes.net/blog/data-annotations-for-entity-framework-4-entities-as-an-mvc-model/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With