kailash urmliya
How to Return Multiple result set in entity framework
By kailash urmliya in .NET on Oct 05 2017
  • Suresh Kumar
    Nov, 2017 6

    It's achievable, there is a great explanation in MSDN . Check this article, it shows two ways to achieve it:https://msdn.microsoft.com/en-us/data/jj691402.aspx

    • 1
  • Madan Shekar
    Jan, 2019 2

    CREATE PROCEDURE [dbo].[GetAllBlogsAndPosts]ASSELECT * FROM dbo.BlogsSELECT * FROM dbo.Postsusing (var db = new BloggingContext()){// If using Code First we need to make sure the model is built before we open the connection// This isn't required for models created with the EF Designerdb.Database.Initialize(force: false);// Create a SQL command to execute the sprocvar cmd = db.Database.Connection.CreateCommand();cmd.CommandText = "[dbo].[GetAllBlogsAndPosts]";try{db.Database.Connection.Open();// Run the sprocvar reader = cmd.ExecuteReader();// Read Blogs from the first result setvar blogs = ((IObjectContextAdapter)db).ObjectContext.Translate(reader, "Blogs", MergeOption.AppendOnly); foreach (var item in blogs){Console.WriteLine(item.Name);} // Move to second result set and read Postsreader.NextResult();var posts = ((IObjectContextAdapter)db).ObjectContext.Translate(reader, "Posts", MergeOption.AppendOnly);foreach (var item in posts){Console.WriteLine(item.Title);}}finally{db.Database.Connection.Close();}}

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS