[英]How to get data as DataSet from stored procedure in Entity Framework
I'm using Entity Framework with asp.net. 我正在使用asp.net的Entity Framework。
I add the my database and stored procedure to the ADO.net entity data model. 我将我的数据库和存储过程添加到ADO.net实体数据模型中。
I want get data from the stored procedure preprocessed as DataTable. 我希望从存储过程中获取数据作为DataTable进行预处理。 I create the function import.
我创建了函数import。
and I call it like this 我称之为这样
DataTable user= db.f_GetbyUser((Guid)User.UserId);
But there is error and it says 但它有错误,它说
Cannot implicitly convert type 'System.Data.Objects.ObjectResult' to 'System.Data.DataSet'
无法将类型'System.Data.Objects.ObjectResult'隐式转换为'System.Data.DataSet'
So can you please tell me how can I run the stored procedure and get the data as data set 那么请告诉我如何运行存储过程并将数据作为数据集
There is no direct conversion. 没有直接转换。 You have to either loop thru result and populated datatable/dataset manually in the loop or use the same connection but in real ADO.NET Command object/Adapter objects to fill Dataset.
您必须在循环中手动循环结果和填充的数据表/数据集,或者使用相同的连接,但在实际的ADO.NET Command对象/适配器对象中填充数据集。
But you shouldn't really be needing Datasets in EF Project, if you do use EF - use strong types it generates for you. 但是如果你使用EF,你不应该在EF Project中真正需要数据集 - 使用它为你生成的强类型。
You're mixing technologies here. 你在这里混合技术。 As @yuriy-galanter says, it is technically possible if you hack the data in to a DataSet / DataTable yourself, but you need to reconsider your data access approach and opt for either DataSets, EF (or something even better).
正如@ yuriy-galanter所说,如果您自己将数据存入DataSet / DataTable,技术上是可行的,但您需要重新考虑数据访问方法并选择DataSet,EF(或更好的东西)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.