How to return multiple return types in Function Import RRS feed

  • Question

  • User1081236289 posted


         I have a SP which return multiple tables. In Entity Framework 4, when i try to add multiple return set to FunctionImport, like below

    <FunctionImport Name="GetAllBlogsAndPosts"
      <ReturnType EntitySet="Blogs" Type="Collection(BlogModel.Blog)" /> 
      <ReturnType EntitySet="Posts" Type="Collection(BlogModel.Post)" /> 

    It says error like "ReturnType" tag cannot be added to FunctionImport. 

    Can anyone please tell me as how can i have multiple return types for a function in EF. 


    Thursday, June 25, 2015 3:07 AM


  • User-271186128 posted

    Hi Mayil_Gilli,

    With reference to this article, I found that you must target .NET Framework 4.5 to be able to configure multiple result sets in EDMX. If you are targeting .NET 4.0 you can use the code-based method shown in the previous section.

    So, since you are using Enitity Framework 4, I suggest you could use the following code to access Multiple Result Sets.

    using (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 Designer 
        db.Database.Initialize(force: false); 
        // Create a SQL command to execute the sproc 
        var cmd = db.Database.Connection.CreateCommand(); 
        cmd.CommandText = "[dbo].[GetAllBlogsAndPosts]"; 
            // Run the sproc  
            var reader = cmd.ExecuteReader(); 
            // Read Blogs from the first result set 
            var blogs = ((IObjectContextAdapter)db) 
                .Translate<Blog>(reader, "Blogs", MergeOption.AppendOnly);    
            foreach (var item in blogs) 
            // Move to second result set and read Posts 
            var posts = ((IObjectContextAdapter)db) 
                .Translate<Post>(reader, "Posts", MergeOption.AppendOnly); 
            foreach (var item in posts) 

    Best Regards,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 25, 2015 11:28 PM