我想从实体框架的存储过程返回一个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); } }更多推荐
从存储过程的实体框架返回列表
发布评论