Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a MVC3 application and I have a problem with data retrieval . I have a list of data and i need to populate it every time . I have managed to get data and store in list but the problem for me is the StoreProc I use to populate data is itself slow and I need to run the proc time and again . I just need to store the data of list somewhere and access it globally so that i do not need to run the same proc again and again . I have to use same proc to populate data with different views. I have tried this.


I have made a model class and populated data in LIST

XML
public List<ScheduleVO> GetScheduling(int? EmployeeId, string day)
      {
          List<GetSchedulingResult> schObj = pdb.GetScheduling(EmployeeId, null, null).ToList();
          List<ScheduleVO> scheduleObj = new List<ScheduleVO>();
          foreach (var stTime in schObj.GroupBy(x => x.StartTime))
          {
              GetSchedulingResult objSchedulingResult = schObj.Where(x => x.StartTime == stTime.Key).FirstOrDefault();
              DateTime dtStartTime = Convert.ToDateTime(objSchedulingResult.StartTime).Date;
              if (day == "Today")
              {
                  if (dtStartTime == DateTime.Now.Date)
                  {
                      ScheduleVO vo = new ScheduleVO();
                      try
                      {
                          vo.scheduled = DateTime.Parse(objSchedulingResult.StartTime.ToString());
                          vo.ProviderName = objSchedulingResult.ProviderName;
                          vo.Address = objSchedulingResult.Address;
                          vo.Contact = objSchedulingResult.ContactName;
                          vo.Phone = objSchedulingResult.ContactInfo;
                          vo.AssignmentID = int.Parse(objSchedulingResult.Assignments_ID.ToString());
                      }
                      catch { }
                      scheduleObj.Add(vo);
                  }




XML
public List<AssignmentVO> GetAssignment(int? EmpId, DateTime date, string day)
      {
          List<AssignmentVO> AssignObj = new List<AssignmentVO>();

          if (day == "Today" || day == "Tomorrow")
          {
              List<GetSchedulingResult> schObj = pdb.GetScheduling(EmpId, null, null).ToList();
              AssignObj = schObj.Where(x => x.StartTime == date).Select(y => new AssignmentVO() { ItemId = y.WorkItem_ID, Provider = y.ProviderName, HICN = y.HICNumber, Patient = y.PatientsName, DOB = DateTime.Parse(y.DOB.ToString()), Excludes = "Charts before " + y.NoIncludeCodingYearDisplayText }).ToList();
          }
          else if (day == "Previous")
          {
              List<GetPrevSchedulingResult> schObj = pdb.GetPrevScheduling(EmpId, null, null).ToList();
              AssignObj = schObj.Where(x => x.StartTime == date).Select(y => new AssignmentVO() { ItemId = y.WorkItem_ID, Provider = y.ProviderName, HICN = y.HICNumber, Patient = y.PatientsName, DOB = DateTime.Parse(y.DOB.ToString()), Excludes = "Charts before " + y.NoIncludeCodingYearDisplayText }).ToList();
          }
          return AssignObj;




Now I just want to group the results of list and show the result in different manner in view for instance i filtered data with date. But for this I again connected to db and made a list then accessed data. I dont want to use this method because its time consuming and not efficient. Any suggestion to use the data of list globally? lets not make list time and again .
Posted

1 solution

I guess you could store it in a session. Ideally with MVC3, you should be using entity framework. you should also consider just looking at your stored proc and fixing it, if it is so slow.
 
Share this answer
 
Comments
shoebass 1-Feb-12 0:45am    
Dear Christian:
I am also trying to optimize the proc. However,for now I am trying to use caching rather than session. I am not using Entity framework rather using Linq to SQL .

Thanx for your suggestion.
Christian Graus 1-Feb-12 0:46am    
Linq 2 SQL works fine with entity framework, but, either way, it sounds like your proc is where your issues lie.
shoebass 1-Feb-12 3:04am    
Exactly!! If the execution(of data) was fast retrieving same thing in list would not be a problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900