我正在尝试为Ravendb实现IoC(Ninject)并遇到了一些障碍.我正在使用http://www.dotnetguy.co.uk/post/2010/06/12/raven-db-ndash-part-1-ndash-documentsession-per-request-with-structuremap中的代码来提供帮助.
public interface IRavenSessionFactoryBuilder
{
IRavenSessionFactory GetSessionFactory();
}
public class RavenSessionFactoryBuilder : IRavenSessionFactoryBuilder
{
private IRavenSessionFactory _ravenSessionFactory;
public IRavenSessionFactory GetSessionFactory()
{
return _ravenSessionFactory ?? (_ravenSessionFactory = CreateSessionFactory());
}
private static IRavenSessionFactory CreateSessionFactory()
{
Debug.Write("IRavenSessionFactory Created");
return new RavenSessionFactory(new DocumentStore
{
Url =
System.Web.Configuration.WebConfigurationManager.AppSettings[
"Raven.DocumentStore"]
});
}
}
public interface IRavenSessionFactory
{
IDocumentSession CreateSession();
}
public class RavenSessionFactory : IRavenSessionFactory
{
private readonly IDocumentStore _documentStore;
public RavenSessionFactory(IDocumentStore documentStore)
{
if (_documentStore != null) return;
_documentStore = documentStore;
_documentStore.Initialize();
} …Run Code Online (Sandbox Code Playgroud) 有没有办法让Raven通过Id字段对查询结果进行排序,就好像它是整数一样.因此,如果我执行此查询,"cars/2"会出现在"cars/11"之前:
var cars = session.Query<Car>().OrderBy(c => c.ID);
Run Code Online (Sandbox Code Playgroud) 在EmbeddableDocumentStore类上调用Initialize时,我遇到了一个非常令人沮丧的错误.这是一个尝试在c:\ temp\ravenDb启动或初始化RavenDB数据库的WPF应用程序.
我的代码是:
EmbeddableDocumentStore _documentStore = new EmbeddableDocumentStore()
{
DataDirectory = @"C:\temp\RavenDb"
};
using (_documentStore.Initialize())
{
}
Run Code Online (Sandbox Code Playgroud)
相当简单.在调用Initialize()时发生错误.这是完整的错误:
Microsoft.Isam.Esent.Interop.EsentFileNotFoundException occurred
Message=File not found
Source=Esent.Interop
StackTrace:
at Microsoft.Isam.Esent.Interop.Api.Check(Int32 err) in C:\Work\ravendb\SharedLibs\Sources\managedesent-61618\EsentInterop\Api.cs:line 2736
InnerException:
Run Code Online (Sandbox Code Playgroud)
令人沮丧的是,当我创建一个新的WPF应用程序并使用相同的代码进行复制时,它可以正常工作,并且能够初始化和创建基本文件.然后,当我回到我的主WPF应用程序时 - 数据库现在能够初始化(因为文件已经创建),但任何Session.Query调用都会导致以下错误:
System.IO.FileNotFoundException occurred
Message=segments.gen
Source=Lucene.Net
StackTrace:
at Lucene.Net.Store.RAMDirectory.OpenInput(String name) in z:\Libs\lucene.net\src\core\Store\RAMDirectory.cs:line 301
InnerException:
Run Code Online (Sandbox Code Playgroud)
编辑:完整代码:从后台工作者委托中调用:
private void RefreshGrid()
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
if (bw.IsBusy != true)
{
bw.RunWorkerAsync(_domainType);
}
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
e.Result …Run Code Online (Sandbox Code Playgroud) 让我们假设我们有最简单的Map索引:
Map = posts => from post in posts
orderby post.DateTime
select new { Id = post.Id, DateTime = post.DateTime }
Run Code Online (Sandbox Code Playgroud)
OrderBy子句如何影响Map索引结果?如果您的查询未明确提供订单子句,它是否定义了默认文档排序?如果在索引和查询中既没有提供排序子句,那么文档是如何排序的?
这是我的索引代码:
public class InvoiceSummaryView
{
public DateTime DueDate { get; set; }
public string CompanyAddress { get; set; }
public string DebtorName { get; set; }
public float Amount { get; set; }
public bool IsPaid { get; set; }
public string CustomerId { get; set; }
}
public class InvoiceSummaryIndex : AbstractIndexCreationTask<CustomerInvoice>
{
public InvoiceSummaryIndex()
{
Map = invoices => from invoice in invoices
select new { DueDate = invoice.DueDate, DebtorId = invoice.DebtorId, Amount = invoice.Amount };
TransformResults = …Run Code Online (Sandbox Code Playgroud) 我想知道什么是获取搜索记录总数的最佳方法,同时返回Nth 128记录块数据段,这似乎是RavenDb运行时强加的上限.
例如,给定此查询,我还需要知道记录的总数.
var bookmarks = session.Query<Bookmark>()
.OrderByDescending(i => i.DateCreated)
.Skip(pageCount * (pageNumber – 1))
.Take(pageCount)
.ToList();
Run Code Online (Sandbox Code Playgroud)
谢谢你,斯蒂芬
我有一个关于如何在RavenDB上实现"select*from xxx where ..."的相同行为的问题,因为将返回大量文档(索引已经设置).
我听说默认行为是Take(128),对吧?但我想要的是像TakeAll(),因为我不知道实际的数字.如何正确实现?
我能想到的是使用Skip()和Take()直到结束.但这对于这样一个简单的要求来说看起来真的很乏味.此外,它可能超过单个会话的请求数量限制,这是我想知道如何优雅克服的另一个障碍.
非常感谢 :)
我有一个使用文档的应用程序,其中包含字典中的属性列表,出于某种原因,我们需要对这些属性使用静态索引和查询/过滤.
原型看起来像这样:
class Program
{
static void Main(string[] args)
{
IDocumentStore store = new DocumentStore() { DefaultDatabase = "Test", Url = "http://localhost:8081" };
store.Initialize();
IndexCreation.CreateIndexes(typeof(Program).Assembly, store);
using (var session = store.OpenSession())
{
session.Store(new Document { Id = "1", Name = "doc_name", Attributes = new Dictionary<string, object> { { "Type", "1" }, { "Status", "Active" } } });
session.SaveChanges();
}
using (var session = store.OpenSession())
{
// works
var l1 = session.Query<Document, Documents_Index>().Where(a => a.Attributes["Type"] == "1").ToList();
// not working
var …Run Code Online (Sandbox Code Playgroud) 我正在C#中执行raven查询,并使用Where()和Search()扩展方法.我需要这两个功能,因为我只需要返回具有特定Guid字段的索引,以及存在于文本正文中的文本.不幸的是,Where扩展方法似乎与Search扩展方法不兼容.当我将它们组合在一起时,我得到一个像这样的Lucene查询:
Query: FeedOwner:25eb541c\-b04a\-4f08\-b468\-65714f259ac2 MessageBody:<<request*>>
Run Code Online (Sandbox Code Playgroud)
这似乎完全忽略了标准的'MessageBody'部分 - 所以我在'自由文本'中使用的约束并不重要,它不使用它.
我已经单独使用'搜索'进行了测试,并且它可以工作 - 所以它本身就是自由文本搜索的问题 - 只需将两者结合起来.
我正在尝试学习如何使用RavenDB,为此我创建了一个基本的例子.似乎初始化商店和查询需要花费大量时间!
static void Main( string[] args )
{
const bool createNewEntities = true;
var sw = new Stopwatch();
using( var store = new EmbeddableDocumentStore {DataDirectory = "~\\Data"} )
{
sw.Start();
store.Initialize();
sw.Stop();
Console.WriteLine( "Initialized in {0} ms.", sw.ElapsedMilliseconds );
if (createNewEntities)
{
sw.Reset();
sw.Start();
using( var session = store.OpenSession() )
{
sw.Stop();
Console.WriteLine();
Console.WriteLine( "Opened session in {0} ms.", sw.ElapsedMilliseconds );
for( var i = 0; i < 10; i++ )
{
var entity = new EntityA( "Entity A " …Run Code Online (Sandbox Code Playgroud)