I was using EF 4.x database-first approach. I have the edmx file and it generated the C# class that derived from EntityObject. I have an ASP.NET MVC 4 application that uses the generated class as model. The client validation that validates the required fields worked fine.
Now I moved to EF 5 and used the DbContext generator, it generates the POCO C# class. I found that the required field validation no longer works in EF 5.
I think the problem is that in EF 4.x EntityObject generator, the generated class has [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)] attribute. However in the EF 5.x POCO class, no data annotation attributes are generated. So the required field information is lost.
So my questions are:
- Why does the EF 5.x DbContext generator not generate
[Required]annotations from the edmx file? - Where is the right place to put these data annotations? Should I modify the .tt file to generate the [Required] attribute? Or manually write a [MetadataType] partial class and define data annotation attributes in a separate class?