Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RavenDB系列_Ravendb - Fatal编程技术网

RavenDB系列

RavenDB系列,ravendb,Ravendb,我正在努力解决RavenDB中的include函数。在我的模型中,我有一篇博文,上面有一个评论列表。此列表中使用的注释类包含对用户的引用 public class BlogPost { public string Id { get; set; } public List<Comment> Comments { get; set; } public BlogPost() { Comments = new List<Commen

我正在努力解决RavenDB中的include函数。在我的模型中,我有一篇博文,上面有一个评论列表。此列表中使用的注释类包含对用户的引用

public class BlogPost
  {
    public string Id { get; set; }
    public List<Comment> Comments { get; set; } 
    public BlogPost()
    {
        Comments = new List<Comment>();
    }
  }

public class Comment
{
    public string Id { get; set; }
    public string Text { get; set; }
    public string UserId { get; set; }
}
公共类BlogPost
{
公共字符串Id{get;set;}
公共列表注释{get;set;}
公共博客帖子()
{
注释=新列表();
}
}
公开课评论
{
公共字符串Id{get;set;}
公共字符串文本{get;set;}
公共字符串用户标识{get;set;}
}
我想做的是获取blogpost并获得一个评论列表,其中包含编写评论以显示在UI中的用户的详细信息,而无需为每个用户查询服务器(N+1)


对于如何解决这个问题,我很乐意提供一些建议。谢谢

您可以使用以下方法来实现:

  session.Include<BlogPost>(b=>b.Comments.Select(x=>x.UserId)).Load(1);
session.Include(b=>b.Comments.Select(x=>x.UserId)).Load(1);
我想我能回答你的问题

您可以一次加载多个文档:

var blogSpots = session.Include<BlogPost>(x => x.Comments.Select(x=>x.UserId))
    .Load("blogspot/1234", "blogspot/4321");

foreach (var blogSpot in blogSpots)
{
    foreach (var userId in blogSpot)
        // this will not require querying the server!!!
        var cust = session.Load<User>(userId);
}
var blogpots=session.Include(x=>x.Comments.Select(x=>x.UserId))
.Load(“blogspot/1234”、“blogspot/4321”);
foreach(blogSpots中的var blogSpot)
{
foreach(blogSpot中的var userId)
//这将不需要查询服务器!!!
var cust=session.Load(userId);
}