如何通过 RIA 服务从客户端传递动态搜索参数?

发布于 2024-08-11 01:22:25 字数 992 浏览 2 评论 0原文

我有一个使用 EF 模型运行 RIA 服务的 C#.NET Silverlight 3.0 客户端。我正在尝试在客户端上设置一个高级搜索系统,以便用户可以说,我希望字段(属性)“Foo1”具有值“Bar1”等。

我想使用类似于 这个。问题是我无法将 IQueryable 作为 ServiceOperation 参数或域服务参数传递。 IE 这不起作用:

[ServiceOperation()]
public int GetFooCount(string category, IQueryable<Foo> search)
{
    int fooCount;
    if (search != null)
    {
        IQueryable<Foo> filteredFooSet = this.Context.FooSet.Intersect(search);
        fooCount = (from foo in filteredFooSet
                    where foo.Category == category
                    select foo).Count();
    }
    else
    {
        fooCount = (from foo in this.Context.ContactSet
                    where foo.Category == category
                    select foo).Count();
    }

    return fooCount;
}

任何人都可以建议一种使这种方法发挥作用的方法或替代(更好)的方法吗?目标是灵活的搜索控件,可以应用于多个特定实体类型。

I have a C#.NET Silverlight 3.0 client running RIA Services with an EF model. I'm trying to set up an advanced search system on the client such that the user can say, I want field (property) "Foo1" to have value "Bar1," etc.. .

I'd like to use a flexible, dynamic approach similar to this one. The problem is I can't pass IQueryable as a ServiceOperation parameter or as a domain service parameter. I.E. This doesn't work:

[ServiceOperation()]
public int GetFooCount(string category, IQueryable<Foo> search)
{
    int fooCount;
    if (search != null)
    {
        IQueryable<Foo> filteredFooSet = this.Context.FooSet.Intersect(search);
        fooCount = (from foo in filteredFooSet
                    where foo.Category == category
                    select foo).Count();
    }
    else
    {
        fooCount = (from foo in this.Context.ContactSet
                    where foo.Category == category
                    select foo).Count();
    }

    return fooCount;
}

Can anyone suggest either a way to get this approach to work or an alternative (better) approach? The objective is a flexible search control that can be applied to more than any single specific entity type.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

最笨的告白 2024-08-18 01:22:25

我认为你最好的选择是使用 动态 Linq 库。使用该库,您可以将 where 子句作为字符串传递,然后使用该库将其用于 EF 数据。

I think your best bet would be to use the Dynamic Linq Library. Using that library you could pass your where clauses as string and then use the library to use that against your EF data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文