如何从web.api获取大量数据? [英] How do I get the huge data from web.api?

查看:157
本文介绍了如何从web.api获取大量数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 web.api 的新手。我有两个案例,两个案例都会相同。



案例:1 在单一LINQ中获得结果。

案例:2 首先从每个表中获取所有数据并执行LINQ。



哪种方式最好非常庞大的数据?我有像POSTS,评论和回复一样的数据,就像facebook一样。



我听说对于大量数据我们需要分页。如果,请指导我。



我尝试过:



案例:1

 var query =(来自db.TblPost中的p其中(来自db中的q)。 TblThread其中q.LocationLocationid == locationID&& q.CategoriesCategoryid == categoryID select q.Threadid).Contains(p.ThreadThreadid)在p.ThreadThreadid上的db.TblThread中加入r等于db.TblUser中的r.Threadid join s on p.UserUserid equals s.Userid join in db.TblCategories on r.CategoriesCategoryid equals t.Categoryid join in 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(); 





案例:2



列表< TblPost> _tblPost = new List< TblPost>(); 
_tblPost =(来自db.TblPost中的p选择p).ToList();

列表< TblThread> _tblThread = new List< TblThread>();
_tblThread =(从db.TblThread中的p选择p).ToList();

列表< TblUser> _tblUser = new List< TblUser>();
_tblUser =(从db.TblUser中的p选择p).ToList();

列表< TblLocation> _tblLocation = new List< TblLocation>();
_tblLocation =(从db.TblLocation中的p选择p).ToList();

列表< TblCategories> _tblCategory = new List< TblCategories>();
_tblCategory =(从db.TblCategories中的p选择p).ToList();


var query =(来自_tblPost中的p其中(来自_tblThread中的q,其中q.LocationLocationid == locationID&& q.CategoriesCategoryid == categoryID select q.Threadid).Contains (p.ThreadThreadid)在_tblThread上连接r.phreadThreadid等于r.Threadid连接s在_tblUser上p.UserUserid等于s.Userid连接t在_tblCategory上r.CategoriesCategoryid等于t.Categoryid连接你在_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();

解决方案

根据您的查询,方法1的性能更好,因为它不会创建很多对象,但查询2更具可读性。所以我会说查询2.



关于分页(大数据的好方法)请检查下面的实现:



带有分页的Web Api

Hi, I'm new to web.api. I've two cases and both cases will result the same.

case: 1 Getting the result in single LINQ.
case: 2 First get the all the data from each table and executing LINQ.

Which is the best way to get the very huge data fastly? I've data like POSTS, Comments and replies just like facebook.

And as i heard that for huge data we need to have pagination. If YES please guide me regarding that.

What I have tried:

Case: 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();



case: 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();

解决方案

As per your queries, the approach 1 is better by performance as it doesn't create objects a lot but query 2 is more readable. So I will say query 2.

Regarding Pagination (a good approach for huge data) please check the implementation below:

Web Api With Pagination


这篇关于如何从web.api获取大量数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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