Entity Framework Model/Database First Validation with MVC3

asp.net-mvc entity-framework

Question

For my application, I want to utilize MVC 3 and the Entity Framework.

The model will be kept in a separate assembly from the MVC application.

I have to decide whether to utilize code first or the EF to create my entities.

I may adorn members with [Required] and other symbols using code first. But what if EF has already created entities from the DB? How would I go about adding those attributes?

It will save me a lot of time to have EF construct my entities, but I want MVC to automatically fill in the validation based on how I've decorated my members. Is this all making sense? If so, how would I go about doing that?

1
9
7/21/2011 11:16:00 AM

Accepted Answer

Then, MetadataTypeAttribute is employed. You may use it in combination with incomplete classes to get the desired effects.

Additionally, if I were in your position, I would do additional study before choosing between Database First and Code First approaches. There are many more differences between the two ways than only saving time while producing entities. In order to save time, you may build code-first entities from a database using the simple program Power tools by EF.

11
7/21/2011 11:30:17 AM

Popular Answer

Instead of constructing your entities automatically, I advise using Code First or converting an existing database to POCO's classes (not generating the entities, just creating them by hand and mapping them to the existing database)

Zzz-9-Zzz was discussed by Scottgu.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow