How to Switch ORM in Repository Pattern (C# .NET MVC)?

I have been searching on it how to switch ORM using repository pattern, and i was not able to find "examples/sample codes" of it so i can study with that. 

I believe my search keywords were wrong (ex. How to switch from EF to ADO.NET using Repo pattern and etc), thats why I can not find an article that talks about it.

Lets say we implement repository pattern with Entity Framework.

Is it repo pattern tightly coupled in Entity Framework? or

Do I need to create another Data Access Layer that talks for ADO.NET/or DAPPER/ Nhibernate?(for example)

Thanks in Advance.

Asked by:- EmmanuelReal
: 3156 At:- 6/27/2018 5:05:51 PM
ASP.NET C# Repository Pattern

2 Answers
profileImage Answered by:- vikas_jk

I don't think you need to add any ORM layer in Repository pattern, after reading your question details, looks like you are already using Entity framework but Code first approach. ADO.NET is used to map your database table into your project using Database first approach.

So, if you want to add ADO.NET ORM in Repository pattern , here is the link which may help

If you dont' want to use ADO.NET ORM here is the example for it using EF (But not any ORM)

Repository pattern without any ORM

If you are looking for exact migration process unfortunately I wasn't able to find any exact solution for that.

At:- 6/28/2018 9:05:12 AM

profileImage Answered by:- EmmanuelReal

Yes, currently i am using EF. But my question on my mind is what if I switch to EF to ADO.Net.

They say repository pattern helps you to abstract and able to switch orm later. I just want to test it out if my repository pattern is correct by switching EF to ADO.Net or Dapper or Nhibernate and etc with sample code and implementation without affecting the EntityFramework to enable me to switch back and forth to different orms/databases.

I am thinking (dont know if i am right but i believe not) to create another implementation for ADO.NET of the repositories because the only one will still the same is the repository interfaces . They (referirng to and ef) both inheriting to the same repositories but different implementation. I am thinking was AdoNETContext and EFContext. So my Controller will not be touched only the Injection and DAL if ever.

At:- 6/28/2018 10:17:57 AM Updated at:- 6/28/2018 10:25:32 AM
When you switch from EF Code first to ADO.NET database first, you need to do same Code changes like you do without Repository pattern, benefit of using repository will be you just need to change code in only one level where are you are accessing database, other projects in your solution remain's same. 0
By : vikas_jk - at :- 6/29/2018 7:31:02 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use