问题描述
我将Silverlight 4与WCF RIA服务(带EF4的域服务)一起使用.现在,我想添加一个功能,该功能允许用户根据用户选择的条件查询数据(临时查询).我发现:
I use Silverlight 4 with WCF RIA Services (domain services with EF4). Now I'd like to add a functionality, which allow an user to query data based on the criteria user selected (ad-hoc query). I've found that:
-WCF RIA服务不允许匿名类型,因此无法进行linq投影.
-WCF RIA Services doesn't allow anonymous types, so linq projection isn't possible.
-公开OData没有多大帮助,因为您不能在客户端过滤数据.
-Exposing OData doesn't help (much), because you can't filter data at client-side.
搜索Internet时,似乎可以使用以下链接中描述的动态linq库:
Searching Internet, it seems I can use dynamic linq library described in the following link:
简而言之,以上链接显示了如何将搜索谓词传递给服务器,以及如何在服务器端执行查询.但是如何返回任意数据呢?匿名类型无法传递,我不希望用户检索所有数据,而只能检索用户选择的那些字段.也许我应该在域服务中序列化我的实体数据,并将其作为原始xml传递?是否有可能?如果是这样,我该怎么办?
In short, the above link shows how to pass search predicate to server, and execute query at the server-side.But how about returning arbitrary data? Anonymous types can't be passed, and I don't want user to retrieve all data, but only those fields user chose. Maybe I should serialize my entity data in domain service and pass it as raw xml? Is it possible? If so, how can I do that?
推荐答案
对于我们的一种情况,我们有一个DomainService操作,该操作返回xml字符串,它看起来像这样:
For one of our scenarios we have a DomainService operation which returns xml strings, it looks something like this:
public IQueryable<WidgetInfo> GetWidgetList()
{
IList<WidgetInfo> widgets = WidgetDatabase.GetWidgets(userId);
return widgets.AsQueryable();
}
其中WidgetInfo
看起来像这样:
public class WidgetInfo
{
[Key]
public int Id;
public string Title;
public string WidgetData; // Contains XML description of data
}
这篇关于使用WCF RIA服务进行动态查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!