4

I am considering using xVal for validation of Entity Framework classes in a MVC application. This involves writing metadata classes as explained in details by Graham O'Neale (http://goneale.com/2009/03/04/using-metadatatype-attribute-with-aspnet-mvc-xval-validation-framework).

I am wondering if there's a way to auto generate such metadata classes using the metadata from the SQL database (for example: not null fields will have [Required] class attribute.

3 Answers 3

3

You could use Code Smith tool www.codesmithtools.com (there is a free version if I remember correctly)

1

I wrote an application that will read an existing database and then generate a Data Annotation Class for every table (excluding aspnet_* and VersionInfo).

http://pfsolutions-mi.com/Product/MetaDataClassGenerator

1
  • I like this app! Thanks!
    – NoWar
    Sep 14, 2016 at 16:57
0

In EF 4, you can easily customize the code generation via a T4 template.

4
  • This requires Visual Studio 2010. I only have Visual Studio 2008.
    – K.A.D.
    Feb 9, 2010 at 18:01
  • There are T4 producers for VS 2008, too. But in your shoes I'd rather make a custom validation provider which understands EF attributes. Actually, I'd really rather use edit models. But that's not what you asked.... Feb 9, 2010 at 19:08
  • I dont mind changing the validation provider. Which validation provider which understands EF attributes? or how to use edit models?
    – K.A.D.
    Feb 10, 2010 at 9:40
  • Validation providers: You'd have to write one. But it's not hard: bradwilson.typepad.com/blog/2010/01/… Edit models: This just means you create a type for the sole purpose of binding your form, and project your entity onto that, instead of binding directly to the entity. Feb 10, 2010 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.