使用和存储列表数据 [英] Using and storing the data of list

查看:92
本文介绍了使用和存储列表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发MVC3应用程序,但是数据检索存在问题.我有一个数据列表,每次都需要填充.我已经设法获取数据并将其存储在列表中,但是对我来说,问题是我用来填充数据的StoreProc本身速度很慢,我需要一次又一次地运行proc.我只需要将list的数据存储在某个位置并全局访问它,这样就不需要一次又一次地运行相同的proc.我必须使用相同的proc来填充具有不同视图的数据.我已经尝试过了.


我做了一个模型类,并在LIST中填充了数据

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

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);
                  }









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;





现在,我只想对列表的结果进行分组,并以不同的方式显示结果,例如,我过滤了带日期的数据.但是为此,我再次连接到db并创建了一个列表,然后访问了数据.我不想使用这种方法,因为它既费时又效率不高.有什么建议使用全局列表数据吗?我们不要一次又一次地列出清单.





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 .

推荐答案

我想您可以将其存储在会话中.理想情况下,对于MVC3,您应该使用实体框架.您还应该考虑查看存储的proc并修复它,如果它太慢的话.
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.


这篇关于使用和存储列表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆