2013-05-02 65 views
0

我想創建一個簡單的索引,其中包括我的文檔中的兩個字段:TraceRowID,LoadDate。不能通過C#添加索引到RavenDB數據庫

所以我創建了以下類:

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 }; 
     } 
    } 
} 

我的模式是 「ServiceTrace」:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace Model 
{ 
    public class ServiceTrace 
    { 
     public int TraceRowID { get; set; } 
     public string StatusDescription { get; set; } 
     public string FullExceptionText { get; set; } 
     public string LoadDate { get; set; } 
    } 
} 

那還有我的DAL:

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管理工作室Silverlight應用程序中添加的任何索引。 有什麼問題?

回答

0

也許你正在尋找在工作室命名的數據庫?通過在這裏不命名特定的數據庫,您正在Raven的系統數據庫中創建索引。

+0

我按頂部欄菜單上的「索引」,並且只有默認值:「Raven/DocumentsByEntityName」索引 – ohadinho 2013-05-02 15:20:44

+1

@ohadinho而在右上角,你看到'數據庫>'或某事其他?請參閱[文檔](http://ravendb.net/docs/2.0/studio/multi-database) – 2013-05-02 22:32:02

+0

我看到數據庫> ohadinho 2013-05-03 21:55:48

相關問題