Entity Framework

Hi people!

Nowadays, I’m learning Entity Framework. Until now, I heard a lot about it, but didn’t have the curiosity to have a look on it.

As I am also a starter, I’ll share my knowledge nice and slow with you. Talked too much so far. Let’s get it started then..

What is Entity Framework?

Entity Framework (EF) is an object-relational mapper (ORM) that enables .NET developers to work with relational data using domain-specific objects. It eliminates the need for most of the data-access code that developers usually need to write. (1)

If we clarify this definition more..

With the help of ORM we can do databases works over objects. Each table in a database has a corresponding object. We can do Insert, Delete, List, Update etc. works safely and quickly using these objects.

Another useful feature of ORM tools is that it eliminates the dependency on databases. You can develop your project using MsSql database and afterwards you can switch to MySql database. What enables you to do it this way is that you do your works without using any sql code in your project.

Why EF?

We may use different ORM tools such as nHibernate in our .Net projects, but we use EF because, it is a Microsoft product and we can use its features much more effectively with the features that comes with Visual Studio.


An existing database or a new one?

With EF, you can both develop your projects with an existing database or you may create a new one.

There are two ways in both databases selections.


If you are going to use an existing database:

1) Database First

  • Reverse engineering model in designer (it will show a model that created considering your database)
  • Classes auto-generated from model (Classes to represent our objects(tables) will be generated automatically from the model which was just shown)

2) Code First

  • You can define classes and mappings via writing codes.


If you are going to work with a new database:

1) Model First

  • Create a model in designer (create a model using boxes and lines in designer)
  • Database created from model
  • Classes auto-generated from model (Classes to represent our objects(tables) will be generated automatically from the model which was just shown)

2) Code First

  • You can define classes and mappings via writing codes.
  • Database is created from you model(code here) for you.


Here is a video on msdn which I benefit from to write this article and I think it will be useful for you also: Introducing Entity Framework

In my next articles, we are gonna develop some easy and real projects, so we will confirm what we have learned in this lesson and learn how to use EF in .Net projects.

Stay tuned to see my next article 😉


1 ) http://msdn.microsoft.com/en-us/data/ef.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *