简体   繁体   English

实体框架4-如何从存储过程中读取多个记录集?

[英]Entity Framework 4 - How to Read Multiple Record Sets From A Stored Procedure?

I have a very simple stored procedure which returns multiple record sets. 我有一个非常简单的存储过程,该过程返回多个记录集。 All of the record sets have aliased columns so they all look the same. 所有记录集都有别名列,因此它们看起来都一样。

Eg 例如

    SELECT TOP 10 FooId AS Id, Name As Name FROM Foos
    SELECT TOP 10 BarId AS Id, Name As Name FROM Bars
         ...

For my EF setup, i'm using POCOs and have my own DataContext (no code-generation). 对于我的EF设置,我使用的是POCO,并且有自己的DataContext(没有代码生成)。

Now, i have created a "Function Import" using the technique detailed here . 现在,我使用此处详细介绍的技术创建了一个“函数导入”。

But the problem is, it's creating a complex type with Id and Name, not a type that can hold multiple collections of Id and Name. 但是问题是,它正在使用Id和Name创建一个复杂的类型,而不是可以容纳Id和Name的多个集合的类型。 Can EF not detect that i am returning multiple record sets? EF无法检测到我要返回多个记录集吗?

So the stored proc gets executed properly, but the only records that come back are from the 1st select statement, the other ones are discarded. 因此,存储的proc可以正确执行,但是返回的唯一记录来自第一个select语句,其他记录则被丢弃。 So i only get back 10 records. 所以我只拿回10条记录。

Here's how im executing the SPROC in my custom DataContext: 这是我在自定义DataContext中执行SPROC的方式:

public ObjectResult<SomeSimpleProc_Result> GetSomeStuff()
    {
        return base.ExecuteFunction<SomeSimpleProc_Result>("SomeSimpleProc);
    }

And the Return Result POCO: 以及返回结果POCO:

public class SomeSimpleProc_Result
    {
        #region Primitive Properties

        public int Id
        {
            get;
            set;
        }

        public string Name
        {
            get;
            set;
        }

        #endregion
    }

The end result is i want to an object which has 0-* objects in it (in the above case, 3 objects). 最终结果是我想要一个包含0- *个对象的对象(在上述情况下为3个对象)。 Each object should have a set of simple objects in it (Id, Name). 每个对象中应具有一组简单对象(Id,名称)。

I think the problem is definitely with the customization of the "Function Import". 我认为问题肯定与“功能导入”的定制有关。 How should i be creating the complex type? 我应该如何创建复杂类型? Or should i be using "Returns a collection of Entities". 还是我应该使用“返回实体集合”。

Any ideas? 有任何想法吗?

I think multiple resut sets are not supported out of the box. 我认为开箱即用不支持多个结果集。 Here is a blog post about using them in EF v1. 是有关在EF v1中使用它们的博客文章。 EF v4 also doesn't support them directly - comments in this article contains following statement by Danny Simmons (he used to be dev manager for EF and Linq-To-Sql): EF v4也不直接支持它们- 本文中的评论包含Danny Simmons(他曾经是EF和Linq-To-Sql的开发经理)的以下声明:

Unfortunately we weren't able to get full support for multiple results into the product this time around. 不幸的是,这次我们无法获得对产品多个结果的全面支持。 We did, however, add the method Translate to ObjectContext which allows you to materialize objects from a DataReader. 但是,我们确实添加了Translate to ObjectContext方法,该方法使您可以从DataReader实现对象。 ... ...

Edit: To make this little bit up to date: EF 4.5 (.NET 4.5 + VS2012) supports stored procedures with multiple result sets but at least in Beta it looked like the support is not implemented in UI and EDMX validation also complained about some problems but at runtime it worked correctly. 编辑:为了使这一点点更新:EF 4.5(.NET 4.5 + VS2012) 支持具有多个结果集的存储过程,但至少在Beta中,它似乎未在UI和EDMX验证中实现,并且还抱怨一些问题但在运行时它可以正常工作。

暂无
暂无

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

相关问题 具有多个结果集的实体框架5存储过程 - Entity Framework 5 stored procedure with multiple result sets 在Entity Framework数据库优先方法中,如何从存储过程返回多个结果集? - In Entity Framework database-first approach how to return multiple result sets from a stored procedure? 如何使用 FromSqlRaw Entity Framework Core 3.1 从存储过程返回多个 SELECT 集 - How to return multiple SELECT sets from a stored procedure using FromSqlRaw Entity Framework Core 3.1 具有读取存储过程的实体框架 - Entity Framework With Read Stored Procedure 无法读取使用实体框架从存储过程返回的值 - Unable to read value returned from a stored procedure using Entity Framework 使用实体框架从存储过程中获取多个字符串输出 - get multiple string outputs from stored procedure using entity framework 如何在 Entity Framework Core 中的多个表上使用联接调用存储过程? - How to call Stored Procedure with join on multiple tables in Entity Framework Core? 如何通过存储过程和多个查询使用Entity Framework创建复杂对象 - How create a complex object with Entity Framework from a Stored Procedure whitin multiple queries 使用Entity Framework 5在1个事务中调用多个存储过程 - Multiple stored procedure calls in 1 transaction with Entity Framework 5 如何从Entity Framework中的存储过程获取DataSet数据 - How to get data as DataSet from stored procedure in Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM