Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do we used it with stored proc that has multiple result sets? #11

Open
xavierjohn opened this issue Feb 26, 2015 · 4 comments
Open

Comments

@xavierjohn
Copy link

How do we used it with stored proc that has multiple result sets?

As mentioned in https://msdn.microsoft.com/en-us/data/jj691402.aspx

Thanks.

@haldiggs
Copy link

I need the answer for this as well. I see the ExecuteStoredProcedure(proc) but how do I grab the result? my result does have multiple result sets as well.

@Fodsuk
Copy link
Contributor

Fodsuk commented May 30, 2015

Unfortunately Entity Framework Extras doesn't support multiple record sets. It only returns the first collection.

@xavierjohn
Copy link
Author

One option could be to wrap the DbDataReader, something like

    public static DbDataReader ExecuteReader(this Database database, object storedProcedure)
    {
        if (storedProcedure == null)
            throw new ArgumentNullException("storedProcedure");

        var info = StoredProcedureParser.BuildStoredProcedureInfo(storedProcedure);

        var cmd = database.Connection.CreateCommand();
        cmd.CommandText = info.Sql;
        cmd.Parameters.AddRange(info.SqlParameters);

        return cmd.ExecuteReader();
    }

jamesra added a commit to jamesra/EntityFrameworkExtras that referenced this issue Apr 2, 2016
@jamesra
Copy link

jamesra commented Apr 2, 2016

I was able to use xavierjohn's suggestion successfully in a fork. In case the next person to find this on Google is as clueless as I was ObjectContext.Translate is used to translate the DbDataReader results into Entity objects. This is the snippet from my code:


using (System.Data.Common.DbDataReader reader = EntityFrameworkExtras.EF6.DatabaseExtensions.ExecuteReader(this.Database, proc))
    {
        Structure[] Nodes = ((IObjectContextAdapter)this).ObjectContext.Translate<Structure>(reader, "Structures", MergeOption.NoTracking).ToArray();
        reader.NextResult();
        StructureLink[] Edges = ((IObjectContextAdapter)this).ObjectContext.Translate<StructureLink>(reader, "StructureLinks", MergeOption.NoTracking).ToArray();

        retval = new NetworkDetails(NodeObjects, ChildObjects, Edges);
        }

jamesra added a commit to jamesra/EntityFrameworkExtras that referenced this issue Apr 2, 2016
jamesra added a commit to jamesra/Viking that referenced this issue Aug 22, 2017
https://github.com/Fodsuk/EntityFrameworkExtras

I don't want to fork it.  I'd rather use the nuget package.
However Viking needs to collect multiple result sets from
stored procedure calls.  I pushed a fix to the repository in
2016 and haven't seen it picked up.  Once multiple result sets
are accepted stop using this fork. Check here for updates:

zzzprojects/EntityFrameworkExtras#11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants