2017-08-18 52 views
2

我有一個我繼承的項目,最近剛剛開始使用RavenDb。我需要將文檔保存到一個已連接的數據庫中,但我需要將該文檔保存到第二個RavenDb。只是想知道我會怎麼做呢?以下是我需要改變的方法。將文檔從MVC網頁保存到第二個RavenDb

[HttpPost] 
    public ActionResult SaveContact(ContactInput input) 
    { 
     var id = getId(); 
     var profile = RavenSession.Load<TechProfile>(id) ?? new TechProfile(); 
     input.MapPropertiesToInstance(profile); 

     // check for existing user 
     if (RavenSession.Query<TechProfile>().Any(x => x.Email == profile.Email && x.Id != profile.Id)) 
     { 
      return Json(new {error = "Profile already exists with that email address.", msg = "Error"}); 
     } 
     RavenSession.Store(profile); 
     return Json(new {error = "", msg = "Success", id = profile.Id.Substring(profile.Id.LastIndexOf("/") + 1)}); 
    } 

回答

3

您需要創建一個會話,將其指向第二個數據庫。 實體沒有綁定到RavenDB中的特定會話,所以你可以這樣做。

+0

非常感謝你,這正是我需要知道的。 – yams