What is entity framework?
Entity Framework (EF) is an object-relational mapper (ORM) that enables us to work with relational data using domain-specific objects. The earlier mechanism of dealing this was ADO.net. Later on MS introduce their first attempt to make an ORM by using LINQ to SQL. Though not asked in the question, however, we feel it is important at this juncture to mention that ORM is a programming technique that contains a set of classes that map relational database entities to objects in a specific programming language.
Some of the advantages of EF or any ORM tool like (EF, NHibernate,Hibernate,GORM etc.) are as under -
- System will create objects as well as track changes on those objects and simplify the process of updating/querying the database thereby eliminating a large chunk of code to be written and maintain by us using ADO.net way.
- Since the mapping between the domain objects and database objects is specified declaratively (SSDL, CSDL and C-S mapping present inside the .Edmx file) and not in code, if we need to alter the database schema, we can minimize the impact on the code.In the EDMX designer we onlt need to refresh and the altered model will be loaded without impacting the earlier OR design.
- We can easily ADD/Delete and object (tables, SP,Views) from the Edmx designer.
- Deferred execution
- Lazy loading and eager loading
- EF can be use with many of DB's (e.g. SQL Server, RavenDB,Oracle, MySQL, Postgres,SQL CE etc.)
- Parent Child relationship mapping can be done very elegantly and eloquently using EF Designer.
- We can create inheritance (e.g. Table-per-Type (TPT) ,table-per-hierarchy (TPH)) in EF.
- Easy stored procedure mapping in terms of functions
- Code will be safer from SQL Injection, Cross-Site Scripting (XSS)
- Code first Migration
- Querying Asynchronously there by speeding up the overall application process
- Database command logging
- Better Transaction Support
- Pluggable pluralisation and singularization service (you can refer to my article
http://www.dotnetfunda.com/articles/show/2260/let-us-learn-pluralizationservices-of-net-40 about what they are )
- Better unit testing
etc.....
EF can be use in two ways.
a) If we are
creating a new project with Domain Driven Design (DDD) , we must go ahead with
Code First Approach .
b) If we are
working on a legacy application , then
database first approac h meets the requirement.
You can refer to my article
http://www.dotnetfunda.com/articles/show/1742/task-management-systemtms as how to use EF in the project.
Hope this helps.
--
Thanks & Regards,
RNA Team
Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator