Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear sir,
how to take last five data (rows) when join multiple table from database using linq.
Posted

Use Order By Desc clause to arrange the rows in descending order and then select the 5 rows using Take(5) method. Column_Name will be the id column or the column you want to sort the table through.

Hope it helps!
 
Share this answer
 
Comments
Abhinav S 29-Dec-11 3:44am    
I was just about to post the same answer.
Ankur\m/ 29-Dec-11 3:47am    
Thanks!
Abhinav S 29-Dec-11 5:28am    
Yes it was indeed a very disappointing boxing day test. :(
C#
var temp = db.Positions.Where(P => P.DeviceID == device.ID);
            List<Position> tempPositions = FilterPosition(temp.ToList<Position>());
            var tt = FilterStops(tempPositions, new TimeSpan(0, 30, 0), 100);
            List<JsonDevicePositionModel> returnPositions = (

                                          from p in tt

                                             select new 
                                                 JsonDevicePositionModel

                                             {
                                                 DeviceID = p.Position.DeviceID,
                                                 Latitude = p.Position.Latitude,
                                                 Longitude = p.Position.Longitude,
                                                 SerialNumber = p.Position.Device.SerialNumber,

                                                 Speed = p.Position.Speed,


                                             }).ToList(); 

            //    }
            return Json(returnPositions, JsonRequestBehavior.AllowGet);

        }
 
Share this answer
 
v2
Comments
RaisKazi 29-Dec-11 3:38am    
Edit: Formatted using "pre" tag.
Ankur\m/ 29-Dec-11 3:44am    
You have copied the question (instead of answer) from StackOverflow site and not even mentioned the source.

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