Posso usar o ADO.NET Data Services com uma fonte de dados LINQ para DataSet?
-
06-07-2019 - |
Pergunta
Nós temos uma aplicação existente que depende fortemente de procedimentos armazenados e DataSets sem tipo. Eu gostaria de manter essa flexibilidade, mas aproveitar as capacidades resto do ADO.NET Data Services. No entanto, quando tento usar o seguinte código para expor o DataSet para 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();
}
}
}
}
}
}
Eu recebo o erro:
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.'.
aqui que ADO.NET Data Services quer que eu decorar o objeto com um DataServiceKey atributo, mas eu não acho que há qualquer maneira para eu fazer isso.
Algumas ideias sobre como eu poderia começar este trabalho? Eu sinto que deveria ser possível ...
Solução
duvido que DataSet
vai ter em qualquer lugar perto de metadados forte o suficiente para ser útil, e você vai precisar classes. Eu fiz alguns potes (começando aqui ) em fazê-lo funcionar com LINQ to SQL que você pode achar útil.