SQL Server Joining data from different data contexts

xe55xuns  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(99)

In my project, I'm using two different data contexts to pass the data to the view from the list.

For that, I wrote the code as this.

private zSqlLink dbs = new zSqlLink();
private zSqlData db = new zSqlData();
// GET: Selfcare

public ActionResult PendingSelfTasks() {
  IEnumerable < SelfCareTasks > pendingTasks = new List < SelfCareTasks > ();

  var list = (from l in dbs.SelfCareTasks 
              where l.Is_Service_Accepted == false && l.Status == true 
              select new {
              l.Id, 
              l.Service_Id, 
              l.Customer_Id, 
              l.Service_End_Date, 
              l.Service_Price
              }
              ).ToList();

  pendingTasks = (from d in list 
                  join c in db.Customer on d.Customer_Id equals c.Id 
                  join ser in db.Services on d.Service_Id equals ser.Id 
                  select new SelfCareTasks 
                  {
                  Id = d.Id,
                  CustomerName = c.Sur_Name + " " + c.Name,
                  ServiceName = ser.Service_NameEng,
                  ServicePrice = d.Service_Price,
                  EndDate = d.Service_End_Date.ToString("dd-MMM-yyyy")
                  }).ToList();

  return View(pendingTasks);
}

First I created a List and add the required main data from Context 1 .

And then Joined that Data with the other context data tables to get the values and pass to the view.

When I debug the code, it returns these errors
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The wait operation timed out

5fjcxozz

5fjcxozz1#

Try to optimize your query. CommandTimeout exception usually occurs when loading large amount of data using joins.

相关问题