• Home
  • About
  • Contact
  • ado.net
  • angular
  • c#.net
  • design patterns
  • linq
  • mvc
  • .net core
    • .Net Core MVC
    • Blazor Tutorials
  • sql
  • web api
  • dotnet
    • SOLID Principles
    • Entity Framework
    • C#.NET Programs and Algorithms
  • Others
    • C# Interview Questions
    • SQL Server Questions
    • ASP.NET Questions
    • MVC Questions
    • Web API Questions
    • .Net Core Questions
    • Data Structures and Algorithms

Friday, August 7, 2020

Development Approach with Entity Framework

 Admin     August 07, 2020     .Net, C#, Entity Framework     No comments   

In this article, I will discuss Development Approach with Entity Framework. The entity framework provides three different approaches when working with the database and data access layer in your application as per your project requirement. These are
  1. Database-First
  2. Code-First
  3. Model-First
Database-First Approach:
We can use the Database First approach if the database schema already existing.

In this approach, we generate the context and entities for the existing database using the EDM wizard.

This approach is best suited for applications that use an already existing database.
Development Approach with Entity Framework

Database First approach is useful:
  1. When we are working with a legacy database
  2. If we are working in a scenario where the database design is being done by another team and the application development starts only when the database is ready
  3. When we are working on a data-centric application
Code-First Approach:
You can use the Code First approach when you do not have an existing database for your application. In the code-first approach, you start writing your entities (domain classes) and context class first and then create the database from these classes using migration commands.

This approach is best suited for applications that are highly domain-centric and will have the domain model classes created first. The database here is needed only as a persistence mechanism for these domain models.

That means Developers who follow the Domain-Driven Design (DDD) principles, prefer to begin coding with their domain classes first and then generate the database required to persist their data.
Development Approach with Entity Framework

Code First approach is useful:
  1. If there is no logic is in the database
  2. When full control over the code, that is, there is no auto-generated model and context code
  3. If the database will not be changed manually
Model-First Approach:
This approach is very much similar to the Code First approach, but in this case, we use a visual EDM designer to design our models. So in this approach, we create the entities, relationships, and inheritance hierarchies directly on the visual designer and then generate entities, the context class, and the database script from your visual model.

Note: The visual model will give us the SQL statements needed to create the database, and we can use it to create our database and connect it up with our application.
Development Approach with Entity Framework

The Model First approach is useful:
  1. When we really want to use the Visual Entity Designer
Choosing the Development Approach for Your Application:
The below flowchart explaining which is the right approach to develop your application using Entity Framework?
Development Approach with Entity Framework

As per the above diagram, if you have an existing database, then you can go with Database First approach because you can create an EDM from your existing database.

But if you don’t have an existing database but you have an existing application with domain classes then you can go with code first approach because you can create a database from your existing classes.

But if you don’t have either existing database or domain model classes then you can go with the model first approach.

In the next article, I will discuss the DB First approach of Entity Framework.

In this article, I try to explain the Development Approach with Entity Framework. I hope this article will help you with your need. I would like to have your feedback. Please post your feedback, question, or comments about this article.

Summary:
I hope this post will be helpful to understand the Development Approach with Entity Framework
Please share this post with your friends and colleagues.
For any queries please post a comment below.
Happy Coding 😉
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Post Older Post

0 comments:

Post a Comment

If you like this website, please share with your friends on Facebook, Twitter, LinkedIn.

Join us on Telegram

Loved Our Blog Posts? Subscribe To Get Updates Directly To Your Inbox

Like us on Facebook

Popular Posts

  • Creating and Working with Database
    Hi friends! In our last post we have seen different approaches how we can connect with SQL Server Management Studio(SSMS). Today, We are g...
  • Introduction to Entity Framework
    Before .NET 3.5 as a developer, we often used to write ADO.NET code to perform CRUD operation with the underlying database. For this, we ne...
  • Recursion And Back Tracking
    In this article, I am going to discuss Recursion And BackTracking in detail. Please read our previous article where we discussed Master Th...
  • Filters in ASP.Net MVC
    Hi friends! Today we are going to discuss about using a very important feature of MVC i.e. “Filters“ . Filters are a unique feature of Asp...
  • Data Parallelism in C#
    Introduction: Hi, in this blog we are going to discuss a very important feature of C# that is data parallelism. Data parallelism means the ...
  • Creating and Working with tables in Sql Server
    Hi friends! In our last post we have seen How to create Database and perform Alter, Delete/ Drop operation on databases in SQL Server. Tod...
  • Entity Types in Entity Framework
    In this article, I am going to discuss the Entity Types in Entity Framework in detail. Please read our previous article where we discussed...

Blog Archive

Contact Form

Name

Email *

Message *

Tags

.Net .Net Core .Net Core MVC Algorithm Angular Anonymous Types Asp.Net Asp.Net MVC Blazor C# Data Structure Database Design Patterns Entity Framework Entity Framework Core Filters Interview Question Management Studio Programming Programs SQL Server SSMS Web API

Copyright © C# Techtics | All Right Reserved.

Protected by Copyscape