如何使用 RIA 服务 QueryBuilder

发布于 2024-12-05 00:55:52 字数 945 浏览 2 评论 0原文

根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北座城市 2024-12-12 00:55:52

我已经认识到自己的错误了。 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.

魔法唧唧 2024-12-12 00:55:52
lo.Completed += (s, e) => 
{     
    foreach(CustomEntity item in lo.Entities)
    {
      list.add(item);
    }
 }; 
lo.Completed += (s, e) => 
{     
    foreach(CustomEntity item in lo.Entities)
    {
      list.add(item);
    }
 }; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文