我对Repository模式还不熟悉(刚从石器时代回来,大家好:-).我的困境是,我需要开发一种我的Windows应用程序应用程序今天与SQLite(SQLite-Net)一起工作的方式,并在不久的将来解决WCF服务(或一些非直接数据库访问).基本上我想轻松切换我的数据访问层的提供者.
我遇到的最好的网站就是这个博客(http://blog.longle.net/2013/05/11/genericizing-the-unit-of-work-pattern-repository-pattern-with-entity-framework- in-mvc /)但是和其他任何地方一样,它仍然有大量的Entity框架,我认为这种框架不适用于我的情况.
有人可以指出我可以进一步研究的可能的解决方案或参考吗?
谢谢
欢迎回来!我希望食物很好。:-)
您可以通过将自己的数据访问层 (DAL) 编写为接口来实现存储库模式,然后分别向 SQLite 和 WCF 编写适配器类(两者都实现该接口)。您的接口将定义查询方法和更新方法。例如,您可以编写以下内容:
public interface IWidgetRepository
{
// Query methods
Widget GetById(string id);
IEnumerable<Widget> GetFeaturedWidgets();
IEnumerable<Widget> GetRecommendedWidgetsForUser(string userId);
// Update methods
void RenameWidget(string id, string newName);
void UpdateWidgetPrice(string id, decimal newPrice);
}
Run Code Online (Sandbox Code Playgroud)
另请参阅类似问题的答案;它涉及更多细节。您的情况与该问题相同,尽管表面上看起来有所不同,因为您来自不同的起点。但一旦您了解了底层模式的工作原理,解决方案是相同的。