Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
631 views
in Technique[技术] by (71.8m points)

linq - Dynamic query with WCF RIA Services

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 Services doesn't allow anonymous types, so linq projection isn't possible.

-Exposing OData doesn't help (much), because you can't filter data at client-side.

Searching Internet, it seems I can use dynamic linq library described in the following link:

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
}

where WidgetInfo looks like this:

public class WidgetInfo
{
    [Key]
    public int Id;
    public string Title;
    public string WidgetData;   // Contains XML description of data
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...