我正在一个项目中实现RavenDB,经过几天尝试数据库,我现在正在构建这个应用程序,但我有一个问题.
我正在为每个实体编写业务层(几乎),并且我有一个处理查询和DocumentStore的唯一存储库类.我对如何沿服务层共享DocumentStore并处理事务感到困惑.
我正在展示一个例子,我试图在单个事务中存储和读取文档.
存储库的一个示例:
public class RavenRepository
{
private static DocumentStore _store;
private IDocumentSession _session;
public RavenRepository(DocumentStore store)
{
_store = (_store==null) ? new DocumentStore() { Url = "http://wsk-gcardoso:8081" } : store;
}
public T SingleOrDefault<T>(Func<T, bool> predicate) where T : BaseModel
{
using (var session = _store.OpenSession())
{
return session.Query<T>().SingleOrDefault(predicate);
}
}
public T Add<T>(T item) where T : BaseModel
{
using (var session = _store.OpenSession())
{
session.Advanced.AllowNonAuthoritiveInformation = this.AllowNonAuthoritiveInformation;
session.Store(item);
session.SaveChanges();
}
return item;
}
public void Initialize() …Run Code Online (Sandbox Code Playgroud) 有没有办法查询RavenDB文档存储并找出陈旧索引的陈旧程度?
从本质上讲,我想要做的是向用户提供结果,同时也给他们一些关于完成索引的概念.
这在大型数据导入场景中会很好.
我能够使用嵌入版本的RavenDb加载几百万个文档,非常漂亮!
现在我正在尝试查询这些项目,并且发现性能不是我预期的,尽可能接近瞬间,而是在相当强劲的机器上超过18秒.
下面,你会找到我的天真代码.
注意:我现在已经解决了这个问题,最后的代码位于帖子的底部.需要注意的是,你需要索引,它们必须是正确的类型,并且需要让RavenDB知道它们.非常满意通过查询引擎返回记录的性能和质量.
谢谢你,斯蒂芬
using (var store = new EmbeddableDocumentStore { DataDirectory = @"C:\temp\ravendata" }.Initialize())
{
using (IDocumentSession session = store.OpenSession())
{
var q = session.Query<Product>().Where(x => x.INFO2.StartsWith("SYS")).ToList();
}
}
[Serializable]
public class Product
{
public decimal ProductId { get; set; }
....
public string INFO2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
编辑
我加了这个班
public class InfoIndex_Search : AbstractIndexCreationTask<Product>
{
public InfoIndex_Search()
{
Map = products =>
from p in products
select new { Info2Index = p.INFO2 };
Index(x => …Run Code Online (Sandbox Code Playgroud) 我正在使用Advanced.LuceneQuery例如
RavenQueryStatistics stats = null;
vm.Products = DocumentSession.Advanced.LuceneQuery<Product>("Products/Index")
.Statistics(out stats)
.Where(searchExpression)
.OrderBy(columnToSortBy)
.Skip((vm.PageIndex - 1) * vm.PageSize)
.Take(vm.PageSize)
.ToArray()
;
Run Code Online (Sandbox Code Playgroud)
用这个索引
public Products_Index()
{
Map = products => from p in products
select new
{
p.ItemNum,
p.BrandName,
p.ProductName,
p.Catalog,
p.UOM,
p.CasePack,
p.AveWeight,
p.CatalogId,
p.HasPicture,
p.INFO2,
p.IsOfflineSupplierItem,
p.IsRebateItem,
p.IsSpecialOrderItem,
p.IsSpecialPriceItem,
p.Price
};
Indexes.Add(x => x.INFO2, FieldIndexing.Analyzed);
Indexes.Add(x => x.CatalogId, FieldIndexing.Analyzed);
Indexes.Add(x => x.HasPicture, FieldIndexing.Analyzed);
Indexes.Add(x => x.IsOfflineSupplierItem, FieldIndexing.Analyzed);
Indexes.Add(x => x.IsRebateItem, FieldIndexing.Analyzed);
Indexes.Add(x => x.IsSpecialOrderItem, FieldIndexing.Analyzed);
Indexes.Add(x => x.IsSpecialPriceItem, FieldIndexing.Analyzed);
Indexes.Add(x …Run Code Online (Sandbox Code Playgroud) 根据CAP定理,分布式计算机系统不可能同时提供一致性,可用性和分区容限。
阅读有关RavenDB的信息后,该数据库似乎同时支持ACID事务和分片。RavenDB如何实现这一目标?
我如何在所有主要的.NET平台上使用嵌入式RavenDB(.NET> = 4.0,Mono,MonoTouch,Mono for Android,[WinRT,MonoGame等]).
它计划在未来支持嵌入式版本的跨平台官方吗?如果是的话:何时?
我从代码中查询RavenDB没有问题,但有时直接快速查找RavenDB会很好.不幸的是,尽管提示它使用Lucene语法,但我无法弄明白.
例如,我有一个RegionLocation文件:
{
"RegionId": 804291854,
"Name": "Miami",
"Description": null,
"DbRowStatus": 0,
"CreatedBy": "Zorro",
"UpdatedBy": null,
"DeletedBy": null,
"CreatedOn": "2013-06-05T18:31:37.4332753",
}
Run Code Online (Sandbox Code Playgroud)
我没有任何运气来查询它.RegionLocation.Name: M*没有结果.知道我做错了什么吗?
如果我在现有的RavenDB会话上运行以下查询:
var result = session.Query<Location>()
.Customize(x => x.WaitForNonStaleResultsAsOfNow())
.Where(l => l.Name = "Home" && !l.Deleted);
Run Code Online (Sandbox Code Playgroud)
RavenDB等待哪些索引?我的假设是它等待查询时所有索引都是最新的; 但是,这是否意味着如果Location其他表上只有一个动态索引而是20个索引,那么我们总是在等待21个索引更新?
或者,我是否误解了该方法的功能?
因此,忽略我们应该使用NoSQL数据库这一事实 - 客户端基础架构要求正在逐渐增加.
我们的数据显然属于非关系模型,但我们必须使用SQL Server 2014来实现持久性.有没有办法将库用于RavenDB或MongoDB与SQL Server之间的持久性?例如,将JSON或BSON存储在SQL Server表中,但使用Mongo或Raven查询和序列化它?
我们最初只是将JSON数据存储在一个列中,但我认为必须有一个更优雅的解决方案.我看到RavenDB支持SQL Server复制,但看起来它不能用于其主要持久性组件.
我们正在运行一个C#ASP.NET MVC Web应用程序.前端是一个KnockoutJS SPA,所以它很乐意绑定到JSON数据.
我目前在为多个环境设置带有dotnet核心的RavenDB时遇到问题。
在StartUp类中,我已将Raven配置为Singleton,并使用IOptions模式将Raven设置绑定到RavenSettings对象。
public virtual void ConfigureServices(IServiceCollection services)
{
Services.AddMvc()
//Add functionality to inject IOptions<T>
services.AddOptions();
// App Settings
services.Configure<RavenSettings>(Configuration.GetSection("Raven"));
//services.Configure<RavenSettings>(settings => Configuration.GetSection("Raven").Bind(settings));
// .NET core built in IOC
services.AddSingleton(DocumentStoreHolder.Store);
services.AddSingleton<IConfiguration>(Configuration);
}
Run Code Online (Sandbox Code Playgroud)
这是我的默认应用设置。
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Raven": {
"Url": "x",
"DefaultDatabase": "x"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试将设置从appsettings绑定到...的类。
public class RavenSettings
{
public string Url { get; set; }
public string DefaultDatabase …Run Code Online (Sandbox Code Playgroud) ravendb ×10
c# ×2
nosql ×2
.net-core ×1
cap ×1
indexing ×1
mongodb ×1
mono ×1
sql-server ×1
xamarin.ios ×1