如何通过 RIA 服务从客户端传递动态搜索参数?
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你最好的选择是使用 动态 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.