how to design Repository pattern to be easy switch to another ORM later?

核能气质少年 提交于 2019-12-04 07:30:55

Inc Wall o' Text

What you're doing is right, your code would be applied to each repository.

As you stated, the purpose of the Repository pattern is so you can interchange the way the data is delivered to your application without having to refactor your code in your application (UI/delivery layer).

Take for example, you decide to switch to Linq to Entities or ADO.NET.

All you would need is to write the code for the ORM you'll be using (having it inherit the proper Interface), then have your code use that repository. Of course you would need replace all references of the old repository or rename/replace your old ORM repositories so that your application uses the proper ones (Unless you're using some type of IoC container, in which you would specify which repository to pass).

The rest of your application would continue to run properly since all the methods you used to get/edit your data will return the proper objects.

In layman's term, the repositories will give your application the data it needs the same way. The only difference is how that data is retrieved from your database (ADO.NET/Linq to something etc.)

Having your classes inherit the Repository Interfaces is a hard-constraint making sure they output the data in a uniform fashion that agrees with the way your application uses it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!