可以使用库模式+存储过程?如果/可他们返回的IQueryable? [英] Possible to use the Repository Pattern + Stored Procedures ? Should / can they return IQueryable?

查看:180
本文介绍了可以使用库模式+存储过程?如果/可他们返回的IQueryable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Repository模式返回的IQueryable℃的大风扇; T> 的对象。然后,我让我的服务层确定什么做什么(例如,通过XXX,为了通过YYY,项目成ABCD等过滤器)。

I'm a big fan of using the Repository pattern to return IQueryable<T> objects. I then let my services layer determine what does what (eg. filter by XXX, order by YYY, project into ABCD, etc).

不过,我有一些铁杆DB的东西,所以我把它全部包裹成一个存储过程。工作正常。我知道EF可以执行存储的特效..但我不知道如何融入一个Repository模式的数据层。

But I've got some hardcore DB stuff, so I've got it all wrapped up into a Stored Procedure. Works fine. I know EF can execute stored procs .. but I'm not sure how this fits into a Repository Pattern data layer.

没有人有任何的例子/建议的?我是否让库方法执行存储过程,然后我返回的结果(如的ICollection&LT;富&gt;作为AsQueryable已 ..所以服务层,然后只查询上结果如何呢?

Does anyone have any examples / suggestions? Do i let the repository method execute the stored procedure, and then i return the result (eg. ICollection<Foo> as AsQueryable .. so the service layer then just queries on that result?

推荐答案

我建议去前进,正是这样做的。安装在存储过程中的EF模型,返回任何实体,它需要,然后在您的存储库中创建一个get,解决什么是存储过程使用。在数据的返回的差发生的DAL内侧(在这种情况下,EF型),版本库仍在访问上下文查找并返回数据。

I would suggest going ahead and doing just that. Setup the stored procedure in the EF model, returning whichever entity it needs to, then in your repository create a get that addresses what the stored procedure is using. The difference in how the data is returned is occurring inside your DAL (in this case the EF model), your repository is still accessing a context to find and return data.

我在做类似的事情,现在,这是我能想出的最佳解决方案。它让我继续做的EF模型我的数据访问,并保持从模型正在收集数据的方式我的仓库分开。该库仍茫然不知如何模型得到的数据和应用程序的其余部分将不会看到任何有关资源库的功能不同。

I am doing something similar right now and that was the best solution I could come up with. It allowed me to continue doing my data access at the EF Model and keep my repository separated from the way the model is collecting the data. The repository is still clueless about how the model gets the data and the rest of the app won't see anything different about the repository functions.

这篇关于可以使用库模式+存储过程?如果/可他们返回的IQueryable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆