Application Models

Approach

Code first

Developer role

Design entities and verify/customize generated migrations

DBA role

Verify schema definitions and changes

Migrations

Per commit

Scaffolding

N/A

Repo

Track entities, DbContext, and migrations

Approach

Database first

Developer role

Reverse engineer after changes and verify generated entities

DBA role

Inform developers when the database changes to re-scaffold

Migrations

N/A

Scaffolding

Per schema change

Repo

Track extensions/partial classes that extend the generated entities

Approach

Hybrid

Developer role

Update fluent configuration to map whenever entities or database change

DBA role

Inform developers when the database has changed so they can update entities and model configuration

Migrations

N/A

Scaffolding

N/A

Repo

Track entities and DbContext

Code First Approach

In the ASP.NET MVC framework, the code-first approach is a development model where you first write the code that creates the data access layer, then you write the code that creates the controllers and views.

In the code-first approach, you create a model, which is a class that represents the data in the application. Then you create a data access layer, which is a set of code that reads and writes data to a data store.

Note that a code-first approach does not have to use a database. You could use the code-first model to create any kind of data.

  1. Install NuGet Packages

  2. Create Model Classes

  3. Configure the Database

  4. Create Database using Migration

  5. Update Database using Migration

Last updated

Was this helpful?