简体   繁体   English

如何从Entity Framework中的存储过程获取DataSet数据

[英]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(或更好的东西)。

More information 更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用存储过程在Entity Framework中获取数据集合 - How to get a collection of data in Entity Framework using stored procedure 如何首先从实体框架+数据库中的存储过程中获取结果 - how to get the result from stored procedure in entity framework + database first 使用Entity Framework从存储过程获取数据 - Getting data from stored procedure with Entity Framework 如何使用SqlDataAdapter从数据集中的存储sql过程中获取数据? - How to get data from stored sql procedure in dataset with SqlDataAdapter? 如何使用实体框架执行存储过程并从存储过程获取输出 - How to execute stored procedure and get output from the stored procedure using Entity Framework 具有实体框架的存储过程中的可空数据集异常 - Nullable DataSet Exception in a Stored Procedure with Entity Framework 如何从实体数据向导以Entity Framework代码优先的方式导入现有存储过程? - How to import existing stored procedure in Entity Framework code-first from entity data wizard? Entity Framework Core 从存储过程中获取数据,然后在没有 DbSet 的情况下转换为视图模型 - Entity Framework Core get data from stored procedure and then convert into view model without DbSet 使用存储过程实体框架从表中获取列表 - get list from table using stored procedure entity framework 实体框架从存储过程获取选择命令对象 - Entity Framework get a select command object from a stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM