Friday, April 10, 2020

What is Entity Framework?


In this article, we will try to answer the following questions
  • What is Entity Framework?
  • What are Entity Framework Approaches?
  • What is Context Class and Entity Class?
So let's get started ....

What is Entity Framework?
Entity Framework is an O/RM Framework, which stands for Object/Relational Mapping Framework.

Purpose: The main purpose of any O/RM or Entity Framework is to automatically generate
  • Database, tables & Stored Procedures
  • Data Access Code
  • Data Saving or Storage Code
Advantage: It helps us to create or update our application quickly and reduce time of production of quality software.

What are Entity Framework Approaches?
The are 3 approaches/methods to use Entity Framework.
  • Database First
  • Code First
  • Model First
NoteDatabase First & Code First are the most commonly used approaches of Entity Framework. So, we will only concentrate on them.

Database First Approach
:
  • We use Database First Approach, when we already have database. 
  • In this approach, Entity Framework generates the context class and entities classes from our existing Database.
Code First Approach:
  • We use Code First Approach, when we don’t have database. 
  • In this approach, we create context class and entities classes ourselves from which Database is generated automatically.
What is Context Class and Entity Class?

Context Class:
  • The context class is used to query or do CRUD operations or any other operations to our database.
  • The context class should be derived from DbContext class.
  • In the case of Database First Approach, the context class is generated for us.
  • In the case of Code First Approach, we create context class ourselves.
Entity Classes:
  • Each entity class represents the corresponding database Table plus all related tables.
  • In the case of Database First Approach, all entity classes are also generated for us.
  • In the case of Code First Approach, we create entity classes ourselves.

No comments:

Post a Comment