如何使用 RIA 服务 QueryBuilder
根据 QueryBuilder 的参数列表,T 对象的 EntityQuery 是查询整形的候选者。然而,我的尝试没有成功。我想知道是否有人知道如何在 T 的 EntityQuery 上使用 ApplyTo 方法以便在客户端上过滤它?
这就是我到目前为止所拥有的:
以下代码片段成功返回存储在特定数据库表中的所有自定义实体。
var ctx = new CustomDomainContext();
var query = ctx.GetAllCustomEntitiesQuery();
var lo = ctx.Load<CustomEntity>(query);
lo.Completed += (s, e) =>
{
var result = lo.Entities.ToList();
};
以下代码片段尝试使用 RIA Services QueryBuilder 来调整上面使用的查询以分隔结果。不幸的是,所有数据仍然被返回。
var ctx = new CustomDomainContext();
var query = ctx.GetAllCustomEntitiesQuery();
var builder = new QueryBuilder<CustomEntity>();
builder.Where(c => c.Id == 1);
builder.ApplyTo(query);
var lo = ctx.Load<CustomEntity>(query);
lo.Completed += (s, e) =>
{
var result = lo.Entities.ToList(); --> Still returns all entities!
};
毫无疑问,我错误地使用了 QueryBuilder。有没有人有将 QueryBuilder 应用于 T 的 EntityQuery 的经验?
According to the QueryBuilder’s parameter list, an EntityQuery of T object is a candidate for query shaping. However, my attempts to do so have been unsuccessful. I’m wondering if anyone knows how to use the ApplyTo method on an EntityQuery of T in order to filter it on the client?
This is what I have so far:
The following snippet succeeds in returning all custom entities stored within a particular database table.
var ctx = new CustomDomainContext();
var query = ctx.GetAllCustomEntitiesQuery();
var lo = ctx.Load<CustomEntity>(query);
lo.Completed += (s, e) =>
{
var result = lo.Entities.ToList();
};
The following snippet attempts to shape the query used above to delimit the results using the RIA Services QueryBuilder. Unfortunately, all of the data is still returned.
var ctx = new CustomDomainContext();
var query = ctx.GetAllCustomEntitiesQuery();
var builder = new QueryBuilder<CustomEntity>();
builder.Where(c => c.Id == 1);
builder.ApplyTo(query);
var lo = ctx.Load<CustomEntity>(query);
lo.Completed += (s, e) =>
{
var result = lo.Entities.ToList(); --> Still returns all entities!
};
No doubt I am using the QueryBuilder incorrectly. Has anyone had any experience in applying the QueryBuilder to an EntityQuery of T?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经认识到自己的错误了。 QueryBuilder 的 ApplyTo 方法不会更改原始 EntityQuery,而是返回一个新的。因此,我所需要做的就是将 QueryBuilder 返回的 EntityQuery 加载到 DomainContext 的 Load 方法中。
I have realised my error. The QueryBuilder's ApplyTo method doesn't alter the orginal EntityQuery but instead returns a new one. Hence, all I needed to do was load the QueryBuilder's returned EntityQuery into the Load method of the DomainContext.