background preloader

ORM

Facebook Twitter

Entity Framework. ADO.NET Entity Framework. Entity Framework (EF) is an open source[1] object-relational mapping (ORM) framework for ADO.NET, part of .NET Framework.

ADO.NET Entity Framework

Overview[edit] The Entity Framework is a set of technologies in ADO.NET that support the development of data-oriented software applications. Architects and developers of data-oriented applications have struggled with the need to achieve two very different objectives. They must model the entities, relationships, and logic of the business problems they are solving, and they must also work with the data engines used to store and retrieve the data.

The data may span multiple storage systems, each with its own protocols; even applications that work with a single storage system must balance the requirements of the storage system against the requirements of writing efficient and maintainable application code. History[edit] A third version of Entity Framework, version 4.1, was released on April 12, 2011, with Code First support. Architecture[edit] EntityFramework. EF4. Repository Pattern with Entity Framework 4.1 and Code First. Introduction A popular pattern for ORM data access is the Repository pattern.

Repository Pattern with Entity Framework 4.1 and Code First

Repositories are currently very popular even in EF for the reasons below: Hide EF from upper layer Make code better testableThe big disadvantage of EF is rigid architecture which can be hardly mocked, so if you want to unit test upper layer you must wrap EF somehow to allow mocking its implementation. The solution I'll show is a very simple implementation of this pattern using EF 4.1 and code first to generate the database. Using the code We will start using a classic implementation of the Repository Pattern. Below the Repository Interface public interface IRepository<TEntity> : IDisposable where TEntity : IEntity { IQueryable<TEntity> GetAll(); void Delete(TEntity entity); void Add(TEntity entity); } As you can see, we got a generic GetAll() method which returns an IQuerable that allows to retrieve and query any entity in our model. Public interface IEntity { int Id { get; set; } } Best .NET ORM Tool. My Considerations Until now I used some custom orm tool (written by me), it was working with stored procedures, because my idea is that the best optimization you may accomplish in sql code.

Best .NET ORM Tool

But now as the project increased and its fonctionality has blow up, I realise that in the future must be used some more adapted orm for supporting Domain Model and Data Mapper, with wich can be used in a more simple fashion the concepts of Unit of Work, Repositories etc. I indeed fell the necessity to pass to this kind of aproach because Transaction Script approach that I used in conjuction with Data Mapping leads in hard maintenace problems when in enterprise application you have sophisticated workflows and transactions to be performed.

My decision was in favor of NHibernate. First of all it's ported from java environment and has proven its viability over the years and the multitude of serios projects based on it. Performance Tests Next I'll show you the results of some tests: List of .NET ORM Tools. nHydrate Code Generation Platform. nHydrate. nHydrate is an object-relational mapping (ORM) solution for the Microsoft .NET platform providing a framework for a relational database to be mapped to .NET objects.

nHydrate

It is designed to alleviate the drudgery software developers experience writing persistence domains. nHydrate is free as an open source project on Codeplex.com under the Microsoft Public License (Ms-PL). nHydrate was originally created in 2003 as a private project to solve the issues with the .NET Framework 1.1. Using ADO.Net Datasets is cumbersome and error prone, so a small generated framework was created to relieve developers of the CRUD work. As a private project it was later inspired by the work of the NHibernate group. nHydrate was a private project from 2003 until 2009. nHydrate is built on the .NET Framework 4.0. From version 5.0 and above, the entire framework has been reworked to use only Entity Framework as it internal data access layer.

Feature summary[edit] History[edit] External links[edit]