Click here to Skip to main content
15,886,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
Posted
Updated 21-Aug-18 18:48pm
v2
Comments
Patrice T 22-Aug-18 0:45am    
Define 'very huge data'
Chanikya494 22-Aug-18 0:48am    
I'll get the data after execution of query
Patrice T 22-Aug-18 0:57am    
Define 'very huge'

1 solution

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
 
Share this answer
 
Comments
Chanikya494 22-Aug-18 0:54am    
What does readable meaning @Er. Puneet Goel
And thanks for the link. But, in that he is doing pagination after getting the data. In my case i need to get few records as pagination requires.
Er. Puneet Goel 22-Aug-18 0:57am    
While writing code we always aim for performance. While achieving this, we sometimes end up writing too messy code. So a code must be a balance between performance and readability (easy to understand)
Chanikya494 22-Aug-18 1:00am    
so, you are suggesting me to do Case 2. If i'm not wrong.
Er. Puneet Goel 22-Aug-18 2:41am    
Definitely

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