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

发布于 2024-08-09 06:33:45 字数 1512 浏览 1 评论 0原文

我们现有的应用程序严重依赖存储过程和非类型化数据集。我希望保持这种灵活性,但利用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野侃 2024-08-16 06:33:45

我怀疑 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文