Cheung
Cheung

Reputation: 15552

ASP.NET MVC create models in fast way by Entity framework?

I am working in ASP.NET MVC 5 with Entity Framework 6.1 in Database First approach.

I starting create Models Class response to each Entity (the tables of database), I feel it is boring task and found that Entity Framework almost done for me.

I expand the *.edmx file and then expand *.tt file, there are many class there and 90% similar to my hand made models. enter image description here

So I start search on Google to see what is the best practice to generate models in smart way. Finally, the following 2 ways I found.

1. Copy all the class corresponding to each database's table to Models folder and remove this line:

System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]

2. Using EF 6.1 Wizard - Code First from Database Which similar to method 1 but come with addition DataAnnotations. enter image description here

There is a 3rd method recommended by Microsoft Doc, Generate the Context with Models inside Models folder and work with, the most simple way, but we know this is the worst one.

So Which method I mention above is proper way to create models?

Upvotes: 0

Views: 369

Answers (1)

K Naga Mallesh
K Naga Mallesh

Reputation: 26

Data base First approach is the best way to create model classes but u don't want annotations for model class at this time you may select 'EF Designer from Database' option from EF wizard choose model step

Upvotes: 0

Related Questions