Skip to main content

Entity Framework – an Introduction

What is ORM framework?

ORM stands for Object relational mapping. The ORM framework allows you map object models of C# classes to relational databases.
ORM framework is useful to maintain databases in the application and saves a lot of time for the developer thus increases developer productivity.  Key points of ORM framework:
  • ORM framework can create classes based on database tables.
  • It can create database tables based on class models.
  • It helps you connect databases and executing SQL queries.

What is Entity Framework?

Entity framework is an ORM (Object relational mapping) framework. This framework is written on the top of ADO.Net, which is part of .NET framework. So, internally entity framework uses ADO.Net.
Entity framework generates model objects and entities based on database tables and vice versa.  You can easily add relationships (like 1 to1 or 1 to many) between different entities. It allows you to perform basic CRUD (create, Read, Update and Delete) operations over the database tables.

Features

  • Less code- Less management: Entity framework reduces the total code to write as compared with ADO.Net, thus increases productivity.
  • All the data access related logic can be written in C#. You can also specify relationships between entities in the code only. So maintaining the databases becomes easy for the developers.
  • The database tables and relationships can be seen in the designers integrated to visual studio. It simplifies the mapping process.
  • Entity framework supports LINQ for queries.

Entity Framework Models

Conceptual Model

Conceptual model includes model classes and relationship between different entities. Conceptual schema definition language (CSDL) defines the conceptual model.

Storage Model

Storage model describes the database description. It is also called the logical model. It includes tables, stored procedures, different keys (primary key and foreign key) and relationships between tables. Storage schema definition language (SCDL) defines the storage model.

Mapping Model

Mapping model implements the relation between conceptual model and storage model. This is the real magic of entity framework. How a class is mapped to a database table and vice versa; these entire things are taken care by mapping model. Mapping specification language (MSL) defines the mapping between conceptual model and storage model.

Architecture

This Framework allows you to create entity model by following approaches:
I will explain details about these three approaches in next articles.
That’s it for this article. Please post your comments for queries and feedback. Thanks for reading.

Comments

Popular posts from this blog

Top 10 ASP.NET Web API Interview Questions

What is ASP.NET Web API? ASP.NET Web API is a framework that simplifies building HTTP services for broader range of clients (including browsers as well as mobile devices) on top of .NET Framework. Using ASP.NET Web API, we can create non-SOAP based services like plain XML or JSON strings, etc. with many other advantages including: Create resource-oriented services using the full features of HTTP Exposing services to a variety of clients easily like browsers or mobile devices, etc. What are the Advantages of Using ASP.NET Web API? Using ASP.NET Web API has a number of advantages, but core of the advantages are: It works the HTTP way using standard HTTP verbs like  GET ,  POST ,  PUT ,  DELETE , etc. for all CRUD operations Complete support for routing Response generated in JSON or XML format using  MediaTypeFormatter It has the ability to be hosted in IIS as well as self-host outside of IIS Supports Model binding and Validation Support for OD...

First, FirstOrDefault, Single, SingleOrDefault In C#

For people who are new to LINQ, it is difficult to understand the difference between First, FirstOrDefault, Single, SingleOrDefault. In this blog, I will explain what to use and when.     I will take a simple example to make you understand practically how these methods work.   Consider a class Employee with properties as Id, Name, and Department. class  Employee {    public   int  Id {  get ;  set ; }    public   string  Name {  get ;  set ; }    public   string  Department{  get ;  set ; } } I have a list of Employees: List<Employee> employeeList =  new  List<Employee>(){    new  Employee() { Id = 1, Name =  "Sunny" , Department =  "Technical"  },    new  Employee() { Id=2, Name= "Pinki" , Department = "HR" },    new  Employee() { Id=3, Name= "Tensy" , De...

Extension methods in C#

Consider the class C# 1 2 3 4 5 6 7 8 9 10 11 12 13          namespace ExtensionMethod      {          public class testClass {              public string sayHello ( ) {              return "Hello" ;            }        }      }     Invoke the above from your form using C# 1 2 3 4 5 6          testClass test = new testClass ( ) ;      MessageBox . Show ( test . sayHello ( ) ) ;     This will show “Hello” in message box. Consider the scenario where you don...