Reputation: 1702
I will start a new project in couple of days which is based on ASP.NET
MVC3
and I don't have enough experience in Web Development.
I just want to know about Entity
Framework. What is Entity
Framework? Why we use it?
and also want to know about Object Relational Mapping
. How is it connect with entity framework?
I've googled but did not get exact idea about it.
I'm very eager to know what's basic concept behind all those things?
Upvotes: 3
Views: 8097
Reputation: 22279
In code, you might want to work with objects in an object oriented fashion.
MyClass obj = new MyClass(); // etc.
However, it might be cumbersome to save data to databases from objects, since you might end up with mapping your object to an SQL query string
// Perhaps with parameter bindings instead, but the idea is the same
"INSERT INTO MYTBL name,phone VALUES(" + obj.Name + "," + obj.Phone + ")";
An ORM framework does this object to SQL mapping by generating SQL statements and the Entity manager will execute them when you need to save or load objects from the database. It comes at the cost of another abstraction layer, but it will make the code easier to write.
Upvotes: 4
Reputation: 12476
Entity Framework is an object-relational mapper. This means that it can return the data in your database as an object (e.g.: a Person object with the properties Id, Name, etc.) or a collection of objects.
Why is this useful? Well, it's really easy. Most of the time you don't have to write any SQL yourself, and iterating is very easy using your language built in functions. When you make any changes to the object, the ORM will usually detect this, and mark the object as 'modified'. When you save all the changes in your ORM to the database, the ORM will automatically generate insert/update/delete statements, based on what you did with the objects.
Upvotes: 8