• 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

  • What is Dependency Injection(DI)
    Hi friends! Today we are going to learn about Dependency Injection and in our last session we have come across Static classes and where it s...
  • C# Programming Examples on Sorting
    Today i am going to tell you some of the Sorting programming questions in C#. Q1- Write a C# program to perform Selection sort. Ans:  Sel...
  • Calling Web API Service in a Cross-Domain Using jQuery AJAX
    In this article, I am going to discuss Calling Web API Service in a Cross-Domain Using jQuery AJAX . Please read our previous article befor...
  • ViewBag in ASP.NET Core MVC
    In this article, I am going to discuss the use of ViewBag in ASP.NET Core MVC application with examples. Please read our previous article ...
  • 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...
  • What is Abstract Class and When we should use Abstract Class
    Hi friends! In our previous sessions we have seen  Difference Between Class and Struct . And in our last session  we learnt Usability of Sec...
  • Binary to Decimal Conversion in C# with Examples
    In this article, I am going to discuss the Binary to Decimal Conversion in C# with some examples. Please read our previous article where w...

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