我可以将 ADO.NET 数据服务与 LINQ-to-DataSet 数据源一起使用吗?
我们现有的应用程序严重依赖存储过程和非类型化数据集。我希望保持这种灵活性,但利用 ADO.NET 数据服务的 REST 功能。但是,当我尝试使用以下代码将数据集公开给 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 属性,但我不认为我可以这样做。
关于如何让这个工作有什么想法吗?我感觉应该是可以的...
We have an existing application that relies heavily on stored procedures and untyped DataSets. I'd like to maintain that flexibility, but leverage the REST capabilities of ADO.NET Data Services. However, when I attempt to use the following code to expose the DataSet to ADO.NET Data Services:
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();
}
}
}
}
}
}
I get the error:
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.'.
I saw here that ADO.NET Data Services wants me to decorate the object with a DataServiceKey attribute, but I don't think there's anyway for me to do that.
Any ideas on how I could get this working? I feel like it should be possible...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑
DataSet
是否会拥有足够强大的元数据来发挥作用,并且您将需要类。我做了一些锅 (从这里开始) 让它与 LINQ-to-SQL 一起使用,您可能会发现它很有用。I doubt that
DataSet
is going to have anywhere near strong enough metadata to be useful, and you'll need classes. I did a few pots (starting here) on getting it working with LINQ-to-SQL that you might find useful.