使用Entity Framework以降序获取列表中的数据

时间:2018-03-24 05:30:34

标签: c# asp.net entity-framework web-services

我正在使用网络服务。我想使用Entity Framework在gridview顶部获取最新更新的数据。当我按降序使用订单时,它会在ToList上显示错误。

public List<GetSet> GetItemInfoByInfo()
{
    List<GetSet> _lst = new List<GetSet>();
    GetSet show = new GetSet();

    using (DBSpotrackFormEntities dbContext = new DBSpotrackFormEntities())
    {
        _lst = dbContext.tblSpotrackLogs.Select(i => new GetSet()
        {
            Id = i.Id,
            Emp_id = i.Emp_id,
            Quantity_produced = i.Quantity_produced,
            Workdone = i.Workdone,
            Ideal_hour = i.Ideal_hour,
            Breakdown_hour = i.Breakdown_hour,
            Activity_code = i.AssestCode,
            Operator_name = i.Operator_name,
            Concern_name = i.Concern_name,
            AssestDesc = i.AssestDesc,
            VechileRegNo = i.VechileRegNo,
            AssestCode = i.Activity_code,
            Hmr_openingReading = i.Hmr_openingReading,
            Hmr_closingReading = i.Hmr_closingReading,
            Kmr_openingReading = i.Kmr_openingReading,
            Kmr_closingReading = i.Kmr_closingReading,
            FuelIssued = i.FuelIssued,
            DateFrom = i.DateFrom,
            DateTo = i.DateTo,
            Work_closetime = i.Work_closetime,
            Work_starttime = i.Work_starttime,

            Hmr_OpnClosDiff = i.Hmr_OpnClosDiff,
            Kmr_OpnClosDiff = i.Kmr_OpnClosDiff,
        }).ToList();
    }

    return _lst;
}

1 个答案:

答案 0 :(得分:-1)

尝试以下:

lst = dbContext.tblSpotrackLogs.Select(i => new GetSet() { } }).ToList().OrderByDescending(p=>p.DateFrom).ToList();