RavenDB - 修补非规范化引用集合
假设我有以下域:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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