开发者

Simple Repository Pattern Question: How to query across multiple repositories efficiently?

If you return IList(T) from your repository ...

How could you efficiently create SQL queries when you join the data together?

Is it REQUIRED to expose IQueryable / IEnumerable data structures for those methods? This to me is bad.

Or

Am I missing some basic concept?

Right now I have a repository methods like:

IList<T> Get( Expression(...) filter, Expression(...) sort, int skip, int ta开发者_JAVA技巧ke)

where null indicates Get All. This works very well until I want to find all Orders of a set of Customers without doing a query for each customer.


It's not required to expose IQueryable<T>, but if you don't then you run into exactly the problem you're describing: You can't further compose the queries.

One solution is to put an entity service layer in front of the repository. The service layer is EF-ignorant, but can do LINQ projections. Projecting in LINQ results in a composed, single DB query.

I have a demo here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜