Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm gonna create a new MVC Application. which is best
EF Code First ?
Model First?
Db First ?

I don't have fixed Database Design ,i may modify existing table may add new table .
so which one is Suitable for my Requirement
Posted
Updated 24-Nov-14 21:49pm
v2

check Code-first vs Model/Database-first[^] based on the comparison you better decide which is bes for your case.
 
Share this answer
 
Quote:
I don't have fixed Database Design ,i may modify existing table may add new table .

As you say here, I anticipate you already have a database and may be you need modification in there in future. So I would suggest to opt for Database first approach. As you just need to add your database connection strings and then Update your model from database. You donot need to create again the classes and then generate the database as you already have the same. Whenever you add a new Table :-
Update model from database-> Check Add table(name of the table)
Then you need to build your solution once and then run custom tool for the .tt file that containes the auto generated classes for your tables in the database.
Whenever you alter any table:-
Update model from database-> Check Refresh select the table name
Then the same procedure mentioned above.
Entity Framework Database First[^]

If you think of recreate a new database, then Code first approach would help you.
Entity Framework Code First[^]

I hope this helps Sir.
thanks
 
Share this answer
 
Hi,

The ADO.NET Entity Framework allows developers to choose any one approach among three possible approaches: Database First, Model First and Code First.

Database First: It is a more data-centric design that is based on an existing database. The Entity Framework is able to generate a business model based on the tables and columns in a relational database. The information about our database structure (store schema), our data model (conceptual model), and the mapping among them is stored in XML in an .edmx file.

Model First: In this approach, we don't have an existing database and the Entity Framework offers a designer that can create a conceptual data model. It also uses an .edmx file to store the model and mapping information. When the model has been created then the Entity Framework designer can generate the database schema that can be used to create the database.

Code First: Whether you have an existing database or not, you can code your own classes and properties that correspond to tables and columns and use them with Entity Framework without an .edmx file. In this approach Entity Framework does not leverage any kind of configuration file (.edmx file) to store the database schema, because the mapping API uses these conventions to generate the database schema dynamically at runtime.

My personal opinion you should go with code first approach because it is used to fast development and developer has full controls on entities. you can check here for my opinion : http://www.itworld.com/article/2700195/development/3-reasons-to-use-code-first-design-with-entity-framework.html[^]


Here is a complete series for code first approach step by step

Relationship in Entity Framework Using Code First Approach With Fluent API[^]

Code First Migrations With Entity Framework[^]

CRUD Operations Using Entity Framework 5.0 Code First Approach in MVC[^]

CRUD Operations Using the Repository Pattern in MVC[^]

CRUD Operations Using the Generic Repository Pattern and Unit of Work in MVC[^]

CRUD Operations Using the Generic Repository Pattern and Dependency Injection in MVC[^]

Thanks
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900