我可以将ADO.NET数据服务与LINQ-to-DataSet数据源一起使用吗?

时间:2009-10-27 17:12:23

标签: wcf-data-services linq-to-dataset

我们有一个现有的应用程序,它严重依赖于存储过程和无类型的DataSet。我想保持这种灵活性,但要利用ADO.NET数据服务的REST功能。但是,当我尝试使用以下代码将DataSet公开给ADO.NET数据服务时:

namespace NewTechnologyDemo {
public class MyDataSource {
    public IQueryable<DataRow> TheDataSet {
        get {
            using (SqlConnection connection = new SqlConnection("server=MySQLServer;integrated security=sspi;database=MyDatabase")) {
                using (SqlCommand command = new SqlCommand("select * from Orders", connection)) {
                    SqlDataAdapter adapter = new SqlDataAdapter(command);
                    DataSet ds = new DataSet();
                    adapter.Fill(ds);

                    return ds.Tables[0].AsEnumerable().AsQueryable();
                }
            }
        }
    }
}
}

我收到错误:

The server encountered an error processing the request. The exception message is 'On 
data context type 'MyDataSource', there is a top IQueryable property 'TheDataSet' whose 
element type is not an entity type. Make sure that the IQueryable property is of entity 
type or specify the IgnoreProperties attribute on the data context type to ignore this 
property.'.

我看到here ADO.NET数据服务希望我用DataServiceKey属性来装饰对象,但我认为无论如何我都不会这样做。

关于如何让这个工作的任何想法?我觉得应该可以......

1 个答案:

答案 0 :(得分:0)

我怀疑DataSet是否会有足够强大的元数据才能发挥作用,而且你需要课程。我在使用你可能会觉得有用的LINQ-to-SQL时做了几句(starting here)