从 MVC 网页将文档保存到第二个 RavenDb

Saving document to second RavenDb from MVC webpage

我继承了一个项目,最近才开始使用 RavenDb。我需要将文档保存到一个已经连接的数据库,但我需要将该文档保存到第二个 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)});
    }

您需要创建一个 second 会话并将其指向第二个数据库。 实体不绑定到 RavenDB 中的特定会话,因此您可以这样做。