Can ASP.NET Entity Framework automatically generate data annotations?

My team is writing a large-scale business site in ASP.NET MVC 4 using a database-based approach. Does anyone know if it is possible to automatically generate data annotations based on a database schema? It seems redundant to manually write buddy metadata classes containing data annotations when the structure needs to know the properties of the database column and create this part of the POCO classes that it creates. Any suggestions would be greatly appreciated!

+4
source share
4 answers

Take a look at LINQ to SQL. You can use it to create a .dbml file in a graphical editor by dragging and dropping tables from the server explorer.

Here's MSDN How to create LINQ to SQL classes in a web project

+1
source

1) The frame does a good job of extrapolating data annotations based on the table structure, but they will not be ideal.

2) Unfortunately, when you reach the point where you want to customize more than the framework, you are stuck with the Buddy classes. They are a bit tedious, but so far the best method I have found for setting data annotation.

3) Too often, I find myself attracted to custom classes and from POCO created ones. The reason usually is the difference between storage and display. On input screens

  • I often split the phone into 3 text fields.
  • Searching for foreign keys requires selection of lists (often added to the model).
  • Often I pass in other values ​​that may be relevant to my View function, but not related to the storage table (display fields, navigation / breadcrumbs).
+1
source

Use the Database First approach with the Entity Framework. You can generate an entity model from an existing database using the entity data model wizard. See http://msdn.microsoft.com/en-us/data/jj206878

0
source

@Kerezo is very similar to what you want to do here: Add a Data Annotation To Entity Framework (or Linq to SQL) generated class

Automatically fails to automatically generate data annotations.

0
source

All Articles