asp.net mvc expand table using stored procedure

Strosala Ioan 61 Reputation points
2021-08-15T07:37:23.603+00:00

Hi. I have two table Customer and Order which are viewed in the following order: in the index view which is paginated with PagedList.Mvc, appears Customer and in the details page view the order. For the index page I have a stored procedure to fill table and the details I have another stored procedure which fill the order table.

I followed the example from this link: https://www.aspsnippets.com/Articles/Implement-Nested-Grid-GridView-in-ASPNet-MVC.aspx, if I use Sql raw we achieved this expansion.

But I want to get this result through using two stored procedure executed by Dapper.
Please help me if possible to get the same result using storage procedures.

Thank you.

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,096 Reputation points
    2021-08-17T02:01:39.01+00:00

    Hi @Strosala Ioan ,
    I found you post the same problem and your codes on the stackoverflow. As far as I think,you could execute two stored procedures and then use QueryMultiple method to map the sql . Just like this:

    public ActionResult Index()      
            {     
                using (IDbConnection conn = new SqlConnection(@"xxx"))      
                {      
                   string sql = @"exec getCustomer;      
                                 exec getOrder;";      
                    using (var multi = conn.QueryMultiple(sql))      
                    {    
                        var t1 = multi.Read<Customer>().ToList();      
                        var t2 = multi.Read<Order>().ToList();     
                    }      
                    return View();      
                }      
            }  
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Cesare Vesdani 11 Reputation points
    2021-08-15T21:41:08.97+00:00

    I do not know how to help you on this issue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.