Can';t通过C#向RavenDB数据库添加索引
我正在尝试创建一个简单的索引,其中包括我文档中的两个字段:TraceRowID、LoadDate 因此,我创建了以下类:Can';t通过C#向RavenDB数据库添加索引,c#,nosql,ravendb,C#,Nosql,Ravendb,我正在尝试创建一个简单的索引,其中包括我文档中的两个字段:TraceRowID、LoadDate 因此,我创建了以下类: using Model; using Raven.Abstractions.Indexing; using Raven.Client.Indexes; using Raven.Client.Linq; using Raven.Client.Document; using System; using System.Collections.Generic; using Syste
using Model;
using Raven.Abstractions.Indexing;
using Raven.Client.Indexes;
using Raven.Client.Linq;
using Raven.Client.Document;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Indexes
{
public class IDLoadDateIndex : AbstractIndexCreationTask<ServiceTrace>
{
public IDLoadDateIndex()
{
Map = serviceTrace => from st in serviceTrace
select new { ID = st.TraceRowID, LoadDate = st.LoadDate };
}
}
}
还有我的朋友:
using Indexes;
using Raven.Client.Indexes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DAL
{
public class DbConnection
{
private readonly static DbConnection instance = new DbConnection();
private Raven.Client.Document.DocumentStore documentStore;
static DbConnection()
{
}
private DbConnection()
{
this.documentStore = new Raven.Client.Document.DocumentStore { Url = "http://btadmins:8080/" };
this.documentStore.Initialize();
IndexCreation.CreateIndexes(typeof(IDLoadDateIndex).Assembly, this.documentStore);
}
public static DbConnection Instance
{
get
{
return instance;
}
}
public Raven.Client.Document.DocumentStore DocumentStore
{
get
{
return documentStore;
}
}
}
}
出于某种原因,当在“CreateIndexes”行上切换到调试模式时,它是成功完成的。但我看不到RavenDB management studio silverlight应用程序上添加了任何索引。
有什么问题吗?也许您正在studio中查找命名数据库?在这里不命名特定的数据库,就是在Raven的系统数据库中创建索引。我按了顶栏菜单上的“索引”,只有默认值:“Raven/DocumentsByEntityName”index@ohadinho在右上角,您是否看到
数据库>
或其他内容?请参阅我看到数据库>你是对的,在数据库>下找到它。所以我应该在我的数据库下创建它,并更改我的代码。。但是为什么当我点击索引时,我在查询文本框中什么也看不到?@Ohadino-在您的代码中,将DefaultDatabase=“MyDatabase”
设置在您现在已有的Url
设置之后。
using Indexes;
using Raven.Client.Indexes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DAL
{
public class DbConnection
{
private readonly static DbConnection instance = new DbConnection();
private Raven.Client.Document.DocumentStore documentStore;
static DbConnection()
{
}
private DbConnection()
{
this.documentStore = new Raven.Client.Document.DocumentStore { Url = "http://btadmins:8080/" };
this.documentStore.Initialize();
IndexCreation.CreateIndexes(typeof(IDLoadDateIndex).Assembly, this.documentStore);
}
public static DbConnection Instance
{
get
{
return instance;
}
}
public Raven.Client.Document.DocumentStore DocumentStore
{
get
{
return documentStore;
}
}
}
}