Open xavierjohn opened 9 years ago
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.
Unfortunately Entity Framework Extras doesn't support multiple record sets. It only returns the first collection.
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();
}
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);
}
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.