【问题标题】:Saving document to second RavenDb from MVC webpage从 MVC 网页将文档保存到第二个 RavenDb
【发布时间】:2017-08-18 16:42:49
【问题描述】:

我有一个继承的项目,我最近才开始使用 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)});
    }

【问题讨论】:

    标签: c# asp.net-mvc ravendb


    【解决方案1】:

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

    【讨论】:

    • 非常感谢,这正是我需要知道的。
    猜你喜欢
    • 1970-01-01
    • 2017-05-05
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多