RavenDB - 修补非规范化引用集合

发布于 2024-11-30 22:43:12 字数 1455 浏览 0 评论 0原文

假设我有以下域:

public class Movie
{
    public string Id { get; set; }
    public string Name { get; set; }
    public List<ActorReference> Actors { get; set; }
}

public class Actor
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Biography { get; set; }
    public string AnotherDetailProperty { get; set; }
}

public class ActorReference
{
    public string Id { get; set; }
    public string Name { get; set; }
}

现在,如果演员的名字发生变化,我想确保所有引用的电影也会更新。因此,我首先创建一个索引,让我查询涉及特定演员的所有电影:

public class Movies_ByActorId : AbstractIndexCreationTask<Movie>
{
    public Movies_ByActorId()
    {
        Map = movies => from movie in movies
                        from actor in movie.Actors
                        select new { ActorId = actor.Id };
    }
}

好的,现在我想触发补丁命令...

Session.Advanced.DatabaseCommands.UpdateByIndex(
    "Movies/ByActorId",
    new IndexQuery
    {
        Query = "ActorId:" + actorWhoseNameHasChanged.Id
    },
    new[]
    {
        new PatchRequest
        {
            Type = PatchCommandType.Modify,
            Name = "Actors",
            Nested = new[]
            {
                // WHAT TO DO HERE?
            }
        }
    },
    allowStale: false);

有人可以帮我完成上面的这个代码块吗,因为我完全不知道,我如何只能更新代表已更改演员的非规范化引用的名称。

恐怕 RavenDB 不支持这种补丁请求,我需要手动加载和存储所有电影,出于性能原因,我肯定想避免这种情况。

Let's assume I have the following domain:

public class Movie
{
    public string Id { get; set; }
    public string Name { get; set; }
    public List<ActorReference> Actors { get; set; }
}

public class Actor
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Biography { get; set; }
    public string AnotherDetailProperty { get; set; }
}

public class ActorReference
{
    public string Id { get; set; }
    public string Name { get; set; }
}

Now, if the name of an actor changes I want to make sure, that all referencing movies are updated as well. Therefore, I first create an Index which let me query all movies in which a specific actor is involved:

public class Movies_ByActorId : AbstractIndexCreationTask<Movie>
{
    public Movies_ByActorId()
    {
        Map = movies => from movie in movies
                        from actor in movie.Actors
                        select new { ActorId = actor.Id };
    }
}

Ok, now I would like to fire the patch-command...

Session.Advanced.DatabaseCommands.UpdateByIndex(
    "Movies/ByActorId",
    new IndexQuery
    {
        Query = "ActorId:" + actorWhoseNameHasChanged.Id
    },
    new[]
    {
        new PatchRequest
        {
            Type = PatchCommandType.Modify,
            Name = "Actors",
            Nested = new[]
            {
                // WHAT TO DO HERE?
            }
        }
    },
    allowStale: false);

Could someone please help me complete this code-block above, since I have absolutely no idea, how I can only update the name of the denormalized references which represent the changed actor.

I'm afraid RavenDB doesn't support this kind of patch-request and I need to load and store all movies manually, which is something I would definitely want to avoid for performance reasons.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

或十年 2024-12-07 22:43:12

RavenDB 不支持基于标准的修补。
您可以在没有非规范化引用的情况下通过在读取时使用 include 来解决您的问题

RavenDB doesn't support doing criteria based patching.
You can solve your problem without denormalized references and by using include at read time

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文