使用本地方法从 DocumentDB 查询数据
Using local methods for querying data from DocumentDB
我的基本存储库中有以下功能
public IEnumerable<T> GetAll(ClaimsPrincipal user)
{
return client.CreateDocumentQuery<T>(collectionLink)
.Where(doc => doc.Type == DocType)
.AsEnumerable()
.Where(doc =>
doc.Owner == user.Id()
|| user.InGroup(doc.Owner)
|| doc.Public);
}
我在 ClaimsPrincipal class 上有两个扩展方法。 Id()
仅 returns .FindFirst("user_id").Value
和 .InGroup(<id>)
检查用户是否拥有文档所在组的组成员资格。
但是,我是否正确地假设一旦我调用 .AsEnumerable()
查询仅使用第一个 where 子句进入数据库,returns 它匹配的所有内容,然后执行第二个 where -客户端的子句?
However, am I correct in assuming that once I call .AsEnumerable() the query goes to the database
不完全是。
当此方法 returns 时,它根本不会访问数据库 。 AsEnumerable()
不会强制执行查询 - 它基本上 只是 转换为 IEnumerable<T>
.
你说得对,第一个 Where
是在数据库中执行的,第二个 Where
是在客户端执行的,但是 "returns everything it matches" 表明这是批量完成的 - 这可能是,但也可能是流式传输。客户端Where
肯定会流,但是IQueryable<T>
实现是否急切获取所有内容是一个实现细节。
如果您真的只对数据库中的过滤器以及本地的过滤器感兴趣,那么您是对的。
我的基本存储库中有以下功能
public IEnumerable<T> GetAll(ClaimsPrincipal user)
{
return client.CreateDocumentQuery<T>(collectionLink)
.Where(doc => doc.Type == DocType)
.AsEnumerable()
.Where(doc =>
doc.Owner == user.Id()
|| user.InGroup(doc.Owner)
|| doc.Public);
}
我在 ClaimsPrincipal class 上有两个扩展方法。 Id()
仅 returns .FindFirst("user_id").Value
和 .InGroup(<id>)
检查用户是否拥有文档所在组的组成员资格。
但是,我是否正确地假设一旦我调用 .AsEnumerable()
查询仅使用第一个 where 子句进入数据库,returns 它匹配的所有内容,然后执行第二个 where -客户端的子句?
However, am I correct in assuming that once I call .AsEnumerable() the query goes to the database
不完全是。
当此方法 returns 时,它根本不会访问数据库 。 AsEnumerable()
不会强制执行查询 - 它基本上 只是 转换为 IEnumerable<T>
.
你说得对,第一个 Where
是在数据库中执行的,第二个 Where
是在客户端执行的,但是 "returns everything it matches" 表明这是批量完成的 - 这可能是,但也可能是流式传输。客户端Where
肯定会流,但是IQueryable<T>
实现是否急切获取所有内容是一个实现细节。
如果您真的只对数据库中的过滤器以及本地的过滤器感兴趣,那么您是对的。