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. 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 Entity Framework enables developers to work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern themselves with the underlying database tables and columns where this data is stored. History[edit] A third version of Entity Framework, version 4.1, was released on April 12, 2011, with Code First support. Architecture[edit] Entity Data Model[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. 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.

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.

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]