2012-05-28 51 views
1

簡單的問題:如何將數據從SQL Server導出到RavenDB?RavenDB export 導入數據到SQL Server

我寫了一個腳本,它從SQL Server獲取數據並存儲在烏鴉中,但其工作非常緩慢。每秒大約2500個插入。

編輯: 我的代碼

for (int i = 0; i < count; i+=8196) 
    { 
     StoreInTaven(WordStats.Skip(i).Take(8196).Select(x => new KeyPhraseInfo(){ 
      Key = x.Word, 
      Id = x.Id, 
      Count = x.Count, 
      Date = x.Date 
     })); 
     GC.Collect(); 
    } 



public static void StoreInTaven(IEnumerable<KeyPhraseInfo> wordStats) 
{ 
    using(var session = store.OpenSession()) 
    { 
      foreach (var wordStat in wordStats) 
      { 
       session.Store(wordStat); 
      } 

      session.SaveChanges(); 
    } 
} 
+0

後的代碼你使用插入到RavenDB。插入的速度是你的代碼的一個因素,也可能是它運行的機器。 – 2012-05-29 05:13:00

回答

1

我只是在做同樣的事情。速度對我來說並不是真正的問題,所以我不知道這是否比你的速度快。

public static void CopyFromSqlServerToRaven(IDocumentSession db, bool ravenDeleteAll=true) 
{ 
    if (ravenDeleteAll) db.DeleteAll(); 

    using (var connection = new SqlConnection(SqlConnectionString)) 
    { 
     var command = new SqlCommand(SqlGetContentItems, connection); 
     command.Connection.Open(); 
     using (var reader = command.ExecuteReader()) 
     { 
      while (reader.Read()) 
      { 
       db.Store(new ContentItem 
          { 
            Id = reader["Id"].ToString(), 
            Title = (string)reader["Name"], 
            Description = (string)reader["ShortDescription"], 
            Keywords = (string)reader["SearchKeywords"] 
          }); 
      } 
     } 
     db.SaveChanges(); 
    } 
} 
+0

我正在做一些像你一樣的事情,但對於1000億行需要很長時間。 – Neir0