asp.netasp.net-mvcvalidationentity-framework-4entity-framework-4.1

How to validate EF 4.0 model with generated DbContext in asp.net mvc?


OK, so I still want to use the schema model from EF 4.0, but I also want the API and flexibility of EF 4.1.

So, in my application, I added DbContext generation code from my current EF 4.0 models.

Now, my questions is what are my options for validating my DbSet (EF 4.1) models without them getting wiped out?

DataAnnotation doesn't seem to cut it because everytime I update my visual model, it COMPLETE WIPES out all my modifications.

Is there a way to do this? Validation repository? Seperate validation layer? Validation inside the repository layers? Examples would be appreciated too.

Please help me. Thanks :)


Solution

  • Using a template generator, it seems possible to do one of the following:

    1. Create a buddy class for each of your entities, and define the buddy class by naming convention in the template.
    2. Figure a way to gen the data annotations, by storing them in a separate source or something.

    Or, use a separate layer. If you are using repositories, you could embed validation there. I chose to have an Orm Validation factory, which pulls in rules matching an entity (either statically or dynamically), and the factory does the work (since that's more along the lines of the singular responsibility principle).