RavenDB:Raven查询未通过文档授权返回正确的计数 [英] RavenDB: Raven Query not returning correct count with document authorization

查看:61
本文介绍了RavenDB:Raven查询未通过文档授权返回正确的计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public class EngineInfo 
  {
    public int Id{get;set;}

    public int? AircraftId { get; set; }

    public string SerialNumber { get; set; }

    public int Position { get; set; }

    public string RegNumber { get; set; }
    }

//这是使用上述模型的代码.我有17,000个使用此模型的文档

// Here is the code which uses the above model. I have 17,000 documents with this model

       ravenSession.Store(new AuthorizationUser
        {
            Id = "Authorization/Users/1",
            Name = "user-1",
            Permissions =
                            {
                                new OperationPermission
                                    {
                                        Allow = true,
                                        Operation = "EngineInfos/View",
                                        Tags = "Company/100"
                                    }
                            }
        });

 1. var query = ravenSession.Query<EngineInfo>();    

///当我记录query.Count()时,我看到所有文档计数,即17000,这忽略了我在before语句中设置的授权.如果我在上述语句中添加where子句,则它可以正常工作,并且我可以看到正确的计数.但是我想获取用户有权访问的所有文档.

// When I log query.Count(), I see all the documents count ie., 17000, This is ignoring the authorization I set in the before statement. If I add where clause to the above statement it is working and I could see the correct count. But I want to get all the documents for which the user has authorization to.

 2. var query = ravenSession.Query<EngineInfo>().ToList();

现在,考虑到授权,我得到了正确的计数.但是问题是除非我提到Take(x),否则它不会返回所有结果.我尝试过

Now, I get the correct count considering authorization. But the problem is unless I mention Take(x), it will not return all the results. I tried with

   RavenQueryStatistics queryStats;
    query.Statistics(out queryStats); 


   queryStats.TotalResults 

我仍然无法获得授权结果.我得到了所有的计数.

I still could not get the authorizes results. I get all the count.

您能帮我弄清楚查找查询结果的TotalCount而不加载所有记录吗?

Could you please help me figuring out in finding TotalCount of the query results without loading all records?

我的要求是在可搜索的ExtJS分页网格中显示所有引擎.我需要知道记录的总数才能显示计算和显示的页数(页数是固定的).

My requirement is to display all engines in an searchable ExtJS paging grid. I need to know the total count of the records to display calculate and display the number of pages(page count is fixed).

推荐答案

这是设计使然,请参见

This is by design, see http://ravendb.net/docs/intro/safe-by-default.

session.Query< Post>().Count()将为您提供服务器上所有帖子的计数,而 session.Query< Post>().ToList().Count()将提供已提取到客户端的帖子数.

session.Query<Post>().Count() will give you the count of all the posts on the server, while session.Query<Post>().ToList().Count() will give the count of the posts that was fetched to the client.

默认情况下,RavenDB将.Take(128)应用于查询,以鼓励您进行分页并且默认情况下是安全的.如果要获得更多,则需要指定要摄取的数量,例如 .Take(1024),但是默认情况下,服务器不会一次返回1024个以上的项目.您可以配置服务器来这样做,但是不建议这样做.您最好使用分页,因为用户无论如何不能一次处理那么多的信息.

By default, RavenDB apply .Take(128) to the query, in order to encourage you to do paging and be safe by default. If you want to get more then that you need to specify how much to take, like .Take(1024), but by default the server will not return more then 1024 items at once. You can configure the server to do so, but this is not recommended. You much better use paging as the user cannot handle that much on info at once anyway.

这篇关于RavenDB:Raven查询未通过文档授权返回正确的计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆