迄今为止与 MSEF 配合使用的最流行的数据访问模式是什么?
与 MSEF 配合使用的最流行的数据访问模式是什么?这是因为我将采用这种模式。
据我所知,NHibernate 存储库是最受欢迎的。
EF的情况如何?
What is the most popular data access pattern to work with MSEF? This is because I am going to adopt that pattern.
In case of NHibernate Repository is the most popular one as far as i know.
What is the case of EF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道最流行的模式是什么,但非常流行的一种模式是存储库(也)。它将检索数据并将其映射到实体模型的逻辑与作用于模型的业务逻辑分开。业务逻辑与构成数据源层的数据类型无关。
您可以在代码项目上找到如何实现它的一个很好的示例。
我认为“工作单元”模式将是一个很好的选择。或者也许您可以尝试将两者结合起来。
I don't know what the most popular pattern is, but a very popular one would be Repository (as well). It separates the logic that retrieves and maps the data to the entity model from the business logic that acts on the model. The business logic becomes agnostic to the type of data that comprises your data source layer.
You can find a nice example of how to implement it here on the Code Project.
I think the 'unit of work' pattern would be a good a alternative. Or perhaps you can try a combination of both.
我建议“Repository”模式提供一组返回 IQueryable<> 的方法。结果。以下是可能的接口示例(最简单的情况之一): http://mikehadlow.blogspot.com/2009/01/should-my-repository-expose-iqueryable.html
实现示例: http://russeleast.wordpress .com/2008/09/20/implementing-the-repository-and-finder-patterns/
与其他答案相比,我想添加的是:您需要将存储库与业务逻辑解耦。这将使 BLL 的单元测试变得更加容易。
I would suggest "Repository" pattern that provides a set of methods returning IQueryable<> result. Here is an example of possible interface (one of the simplest cases): http://mikehadlow.blogspot.com/2009/01/should-my-repository-expose-iqueryable.html
Implementation example: http://russelleast.wordpress.com/2008/09/20/implementing-the-repository-and-finder-patterns/
What I want to add comparing to other answers: you need to decouple your repositories from business logic. This will easier significantly unit testing of you BLL.
工作单元和存储库。
您可以通过 google 搜索 FabrikamShipping - 使用它们的 SaaS 应用程序的参考实现。
Unit of Work and Repository.
You can google for FabrikamShipping - reference implementation of saas app using them.