Code First Approach
In code first approach we will first create entity classes with properties defined in it. Entity framework will create the database and tables based on the entity classes defined. So database is generated from the code. When the dot net code is run database will get created.
- You can create the database and tables from your business objects.
- You can specify which related collections are to be eager loaded, or not be serialized at all.
- Database version control.
- Good for small applications.
- You have to write everything related to database in the visual studio code.
- For stored procedures you have to map stored procedure using Fluent API and write Stored Procedure inside the code.
- If you want to change anything in the database tables you to make changes in the entity classes in the code file and run the update-database from the package manager console.
- Not preferred for Data intensive applications.
Database First Approach
In this approach Database and tables are created first. Then you create entity Data Model using the created database.
- Simple to create the data model
- Graphical user interface.
- Mapping and creation of keys and relationships are easy as you need not have to write any code .
- Preferred for data intense and large applications
- Using an existing database to generate a .edmx model file and the associated code models results in a giant pile of auto generated code.
- When you need to add any functionality to generated model you have to extend the model class generated.