Thursday, August 4, 2011

ToTheEfnhX

As it is very tedious to make a duplicate ASP.NET MVC proof-of-concepts code that supports both Entity Framework and NHibernate, I finally developed an itching desire to abstract away the intricacies of ORMs differences.

On this regard, I made a repository pattern library, so we will now have more time to concentrate on making awesome ASP.NET MVC programs and business logic, instead of attending to each ORM's nuances.


Here's the interface for abstracting away the differences on those ORMs' persistence mechanism


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ToTheEfnhX
{
    public interface IRepository<Ent> where Ent : class
    {
        IQueryable<Ent> All { get; }
        
        void Save(Ent ent, byte[] version);
        Ent Get(object id);
        void Delete(object id, byte[] version);
        void DeleteCascade(object id, byte[] version);

        Ent LoadStub(object id);

        string PrimaryKeyName { get; set; }
        string VersionName { get; set; }
    }
}


On my next post, I'll show you how to use this repository library.

Unit tests:




https://github.com/MichaelBuen/ToTheEfnhX

No comments:

Post a Comment