使用RavenDB实现存储库和服务模式 [英] Implementing the repository and service pattern with RavenDB

查看:74
本文介绍了使用RavenDB实现存储库和服务模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的RavenDB中实现存储库和服务模式时,我遇到了一些困难项目.主要的问题是我的存储库界面应如何显示,因为在RavenDB中,我使用了两个索引进行查询.

I have some difficulties implementing the repository and service pattern in my RavenDB project. The major concern is how my repository interface should look like because in RavenDB I use a couple of indexes for my queries.

比方说,我需要获取父项等于1的所有项.一种方法是使用IQueryable List()并获取所有文档,然后添加where子句以选择父项等于1的项.这看起来像这是一个坏主意,因为我无法在RavenDB中使用任何索引功能.因此,另一种方法是在存储库中使用类似IEnumerable Find(string index,Func predicate)的方法,但这似乎是一个坏主意,因为它不够通用,并且要求我实现此方法,以便从RavenDB进行更改到普通的sql服务器.

Let's say I need to fetch all items where the parentid equals 1. One way is to use the IQueryable List() and get all documents and then add a where clause to select the items where the parentid equals 1. This seems like a bad idea because I can't use any index features in RavenDB. So the other approach is to have something like this, IEnumerable Find(string index, Func predicate) in the repository but that also seems like a bad idea because it's not generic enough and requires that I implement this method for if I would change from RavenDB to a common sql server.

那么我该如何实现通用存储库,但仍能从RavenDB中获得索引的好处?

So how can I implement a generic repository but still get the benefits of indexes in RavenDB?

推荐答案

这篇文章很好地总结了全部内容:

This post sums it all up very nicely:

http://novuscraft.com/blog/ravendb-and-the-repository-pattern

这篇关于使用RavenDB实现存储库和服务模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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