从存储过程的实体框架返回列表

编程入门 行业动态 更新时间:2024-10-19 04:31:09
本文介绍了从存储过程的实体框架返回列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从实体框架的存储过程返回一个int列表。

I'm trying to return a list of int from a stored procedure in Entity Framework.

我创建的存储过程的罚款,并添加入实体框架。我试图将其绑定到一个复杂的类型,但是当我打开函数导入。

I created the stored procedure fine, and added it into Entity Framework. I'm trying to bind it to a complex type of but when I open the function import.

它自动生成一个复杂类型只返回一个int,而不是设置一个结果。

It auto generates a complex type that only returns an int instead of a results set.

有谁知道我怎么可以导入返回一个列表作为一个结果集的实体?

Does anyone know how I can import an entity that returns a list as a result set?

推荐答案

我创造了这个示例存储过程返回列表INT值:

I created this sample stored procedure returning a list of int values:

CREATE PROCEDURE dbo.GetListOfInt AS BEGIN SELECT * FROM (VALUES (42), (4711), (8088), (80286), (80486), (655235)) AS VT(VC) END

然后我加了此存储过程在我的EF 的.edmx 模型,并创造了这个功能导入:

I then added this stored procedure to my EF .edmx model and created this Function Import:

查询存储过程让我发现,它返回一个结果集,包括 INT 值 - 因此,我定义的返回值是的标量的集合:的Int32 的在功能导入对话框

Querying the stored procedure shows me that it returns a result set consisting of int values - I therefore define the return value to be a collection of Scalar: Int32 in the function import dialog.

在这之后,我可以调用存储过程并取回结果是这样的:

After that, I can call that stored procedure and get back the results like this:

using (testEntities ctx = new testEntities()) { ObjectResult<int?> result = ctx.GetListOfInt(); foreach (int intValue in result.AsEnumerable()) { Console.WriteLine("INT value returned: {0}", intValue); } }

更多推荐

从存储过程的实体框架返回列表

本文发布于:2023-11-06 13:54:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:存储过程   实体   框架   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!