我可以从数据库usinq linq中获取最后五行吗 [英] can I take last five rows from database usinq linq

查看:62
本文介绍了我可以从数据库usinq linq中获取最后五行吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,
使用linq从数据库连接多个表时如何获取最后五个数据(行).

dear sir,
how to take last five data (rows) when join multiple table from database using linq.

推荐答案

使用Order By Desc子句以降序排列行,然后选择使用Take(5)方法的5行. Column_Name将是id列或您要对表进行排序的列.

希望对您有所帮助!
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!


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

        }


这篇关于我可以从数据库usinq linq中获取最后五行吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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