我们有一个严重依赖存储过程和无类型数据集的现有应用程序。我想保持这种灵活性,但要利用 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.'.
我在这里看到 ADO.NET 数据服务希望我使用DataServiceKey属性来装饰对象,但我认为无论如何我都不会这样做。
关于如何让这个工作的任何想法?我觉得应该可以。。。