R – how to use Repository pattern to make it easy switch between ORMs


I knew than one of the benefits from using repository pattern make it easy to switch between ORM, for example will implement data access code using Linq to sql and also using Ado.net entity framework, then using Dependency injection switch which one to use.

I saw KIGG doing the same "but its class diagram is complicated a little, at least for me as a beginner in repository pattern"

But i can't find an example describing this issue in details, i saw this example on codeproject its talking about generic repository implementation using Linq to sql, but can't use to switch to use another ORM.

where i can understand this issue? do you recommended an article or have your description?

Best Solution

I think that your repository implimentation will always be tied to whatever ORM or data access method it uses. Where the loose coupling is, is between the business logic (the repository interfaces) and the repository implimentations. You can create a new set of implimentations that meet the interface requirements, but impliment a different data access method. Once that's done it can be as easy as reconfiguring your IoC container to switch between the two...