I'm using Entity Framework with asp.net.
我在使用asp.net的实体框架。
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. I create the function import.
我想要从存储过程中获取数据,作为DataTable进行预处理。我创建函数导入。
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'
不能隐式转换type '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
请告诉我如何运行存储过程并将数据作为数据集
2 个解决方案
#1
1
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命令对象/适配器对象来填充数据集。
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项目中不应该真正需要数据集。
#2
1
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所说,如果您自己将数据压缩到数据集/数据表中,技术上是可能的,但是您需要重新考虑您的数据访问方法,选择数据集EF(或者更好的方法)。
更多的信息
#1
1
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命令对象/适配器对象来填充数据集。
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项目中不应该真正需要数据集。
#2
1
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所说,如果您自己将数据压缩到数据集/数据表中,技术上是可能的,但是您需要重新考虑您的数据访问方法,选择数据集EF(或者更好的方法)。
更多的信息