2017-08-18 51 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