从 WCF 数据服务到 Silverlight 应用程序的动态查询数据? [英] Dynamic query data from WCF Data Service to Silverlight Application?

查看:32
本文介绍了从 WCF 数据服务到 Silverlight 应用程序的动态查询数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Silverlight 应用程序,其中包含一个在多列中列出多个值的窗口.第一列包含要从数据库中检索的字段,第二列包含表名.

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).

我的问题是如何将这些值传递给 WCF 数据服务方法并将无类型数据集返回给调用 Silverlight 应用程序?在运行时之前,我无法知道要获取的列或要使用的表.这意味着我无法定义用于将数据从 WCF 数据服务返回到 Silverlight 的类.

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?

谢谢

推荐答案

Silverlight 没有数据表或数据集结构.但是,您可以使用嵌套列表来伪造它.这家伙将 Silverlight 数据表代码放在一起,还展示了如何将其序列化并通过 WCF 发送:http://blogs.telerik.com/blogs/posts/10-01-22/how_to_serialize_your_datatable_to_silverlight_using_wcf_service.aspx

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

至于将查询发送到服务器,您有几个选择.您可以动态构建 linq 表达式树(与 domaindatasource 在幕后所做的方式相同)并使用它从客户端直接查询.您还可以将序列化形式的搜索参数发送到服务器并在那里构建查询.同样,如果您想使用 LinqToEntities 进行查询,您要么必须构建 linq 表达式树,要么您可以回到老学校,只构建一个 SQL 查询.如果您使用 SQL,请确保防止 SQL 注入.

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.

我还建议您投票支持将数据集/数据表功能添加到 Silverlight,这将使您的解决方案更易于开发.您可以在这里为它投票.

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.

这篇关于从 WCF 数据服务到 Silverlight 应用程序的动态查询数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆