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

What is cookie? Advantages and disadvantages of cookies?

What is cookie? A cookie is a small piece of text file stored on user's computer in the form of name-value pair. Cookies are used by websites to keep track of visitors e.g. to keep user information like username etc. If any web application using cookies, Server send cookies and client browser will store it. The browser then returns the cookie to the server at the next time the page is requested. The most common example of using a cookie is to store User information, User preferences, Password Remember Option etc.It is also one of the common and mostly asked interview questions. Some facts about Cookie Here are a few facts to know about cookies: · Cookies are domain specific i.e. a domain cannot read or write to a cookie created by another domain. This is done by the browser for security purpose. · Cookies are browser specific. Each browser stores the cookies in a different location. The cookies are browser specific and so a cookie created in one browser(e.g in Google Chrome

Code First Getting Started

In this tutorial let us create a simple application to demonstrate the use of entity framework using code first. We are using Visual Studio 2015 and entity framework 6.1.3. You can download Visual Studio community Edition . You should have the basic knowledge of .Net framework, C# and MS SQL Server. In this tutorial, we will create a simple application with a user class.  Our user class will have basic information like name and email address of the user. Create the Project Open Visual Studio. File ->New -> Project Select C# -> Select Console Application Name the application as “EFGettingStarted” Click on OK Install Entity Framework The next step is to install the Entity framework. This can be installed via nuget package console. Click on Tools->Nuget Package manager -> Package Manager Console and type the following command C# 1 2 3   install - package entityframework   This will install the late

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" , Department = "Finance" },    new  Employee() { Id=4, Name= "Bobby" , Department = "Technical" },    new