Dynamic query data from WCF Data Service to Silverlight Application?

為{幸葍}努か 提交于 2020-01-06 08:42:03

问题


I have a Silverlight application that contains a window that lists several values in multiple columns. The first column contains fields to be retrieved from a database, the second column contains table names.

Multiple fields can be selected from the first column and only one field can be selected from the second column. So, the idea is to build a query that can select multiple columns from one of several tables (assume the column names are the same for each table).

My question is how do I pass these values into a WCF Data Service method and return an untyped dataset back to the calling Silverlight application? I will have no way of knowing the columns to fetch or the table to use until run-time. That means I cannot define a class to be used to return the data back from the WCF data service to Silverlight.

Any ideas on how to accomplish this?

Thanks


回答1:


Silverlight doesn't have a datatable or dataset construct. However, you can fake it with nested lists. This guy put together the silverlight datatable code, and also shows how it can be serialized and sent over WCF: http://blogs.telerik.com/blogs/posts/10-01-22/how_to_serialize_your_datatable_to_silverlight_using_wcf_service.aspx

As for getting the query to the server, you have a few options. You can build linq expression trees dynamically (the same way that domaindatasource does under the covers) and use that to query right from the client. You could also send your search parameters in a serialized form over to the server and construct the query there. Again, you'll either have to build linq expression trees if you want to use LinqToEntities for the query, or you could go old school and just build up an SQL query. If you go SQL, make sure you protect against SQL injection.

I could also suggest that you vote for the dataset/datatable feature to be added to silverlight, which would make your solution a little easier to develop. You can vote for it here.



来源:https://stackoverflow.com/questions/6989465/dynamic-query-data-from-wcf-data-service-to-silverlight-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!