使用Web.API表示海量数据的最佳方法是哪种?

时间:2018-08-22 04:12:48

标签: asp.net-web-api

  

案例1:

 var query = (from p in db.TblPost where (from q in db.TblThread 
        where q.LocationLocationid == locationID && q.CategoriesCategoryid == categoryID select q.Threadid).Contains(p.ThreadThreadid) 
        join r in db.TblThread on p.ThreadThreadid equals r.Threadid join s in db.TblUser on p.UserUserid equals s.Userid join t 
        in db.TblCategories on r.CategoriesCategoryid equals t.Categoryid join u in db.TblLocation on r.LocationLocationid 
        equals u.Locationid orderby r.CreatedTime descending 
        select new { p, r.Subject, r.EventAddress, r.EventClosetime, r.EventDate, r.EventDuration, r.EventStarttime, 
        r.EventTitle, r.IseventAllday, r.TargetUsers, r.CreatedTime, s.FirstName, s.MiddleName, s.LastName, t.Name, 
        u.Locationname, r.Isreadonly }).ToList();

OR

  

案例2:

                List<TblPost> _tblPost = new List<TblPost>();
                _tblPost = (from p in db.TblPost select p).ToList();

                List<TblThread> _tblThread = new List<TblThread>();
                _tblThread = (from p in db.TblThread select p).ToList();

                List<TblUser> _tblUser = new List<TblUser>();
                _tblUser = (from p in db.TblUser select p).ToList();

                List<TblLocation> _tblLocation = new List<TblLocation>();
                _tblLocation = (from p in db.TblLocation select p).ToList();

                List<TblCategories> _tblCategory = new List<TblCategories>();
                _tblCategory = (from p in db.TblCategories select p).ToList();


 var query = (from p in _tblPost where (from q in _tblThread where q.LocationLocationid == locationID 
         && q.CategoriesCategoryid == categoryID select q.Threadid).Contains(p.ThreadThreadid) join r in _tblThread on p.ThreadThreadid 
         equals r.Threadid join s in _tblUser on p.UserUserid equals s.Userid join t in _tblCategory on r.CategoriesCategoryid equals 
         t.Categoryid join u in _tblLocation on r.LocationLocationid equals u.Locationid orderby r.CreatedTime descending 
         select new { p, r.Subject, r.EventAddress, r.EventClosetime, r.EventDate, r.EventDuration, r.EventStarttime, 
         r.EventTitle, r.IseventAllday, r.TargetUsers, r.CreatedTime, s.FirstName, s.MiddleName, s.LastName, 
         t.Name, u.Locationname, r.Isreadonly }).ToList();

这两个代码的结果相同。但是,在case 2中,与case 1相比,我得到的结果要快一些。我应该遵循哪一个?

我可以跟随case 2吗?在Web.API中获取海量数据是正确的方法吗?

0 个答案:

没有答案