> For the complete documentation index, see [llms.txt](https://dailyjournal.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dailyjournal.gitbook.io/notes/orms/entity-framework/application-models.md).

# Application Models

<table data-view="cards"><thead><tr><th>Approach</th><th>Developer role</th><th>DBA role</th><th>Migrations</th><th>Scaffolding</th><th>Repo</th></tr></thead><tbody><tr><td><strong>Code first</strong></td><td>Design entities and verify/customize generated migrations</td><td>Verify schema definitions and changes</td><td>Per commit</td><td>N/A</td><td>Track entities, <code>DbContext</code>, and migrations</td></tr><tr><td><strong>Database first</strong></td><td>Reverse engineer after changes and verify generated entities</td><td>Inform developers when the database changes to re-scaffold</td><td>N/A</td><td>Per schema change</td><td>Track extensions/partial classes that extend the generated entities</td></tr><tr><td><strong>Hybrid</strong></td><td>Update fluent configuration to map whenever entities or database change</td><td>Inform developers when the database has changed so they can update entities and model configuration</td><td>N/A</td><td>N/A</td><td>Track entities and <code>DbContext</code></td></tr></tbody></table>

## 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.&#x20;

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.&#x20;

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

{% embed url="<https://medium.com/c-sharp-progarmming/tutorial-code-first-approach-in-asp-net-core-mvc-with-ef-5baf5af696e9>" %}

{% embed url="<https://code-maze.com/net-core-web-api-ef-core-code-first/>" %}
