【问题标题】:Get the record (row) in a table with the most recent (greatest date) LINQ to SQL C#获取具有最近(最大日期)LINQ to SQL C# 的表中的记录(行)
【发布时间】:2011-09-07 09:29:39
【问题描述】:

我有一个名为 tblTrans 的表,它有 4 个字段: ID、CustID、TDATE、姓名

如何在 LINQ to SQL CE 中获取最新或最近的行。我希望查询返回该行的所有字段。 我正在尝试这个,但无法让它工作:

tblTrans retTrans = (从 c by c.TDATE 到 g orderby c.TDATE)

【问题讨论】:

    标签: linq-to-sql


    【解决方案1】:

    试试这个:

    var retTrans = (
            from c in tblTrans
            orderby c.TDATE descending
            select c
        ).FirstOrDefault();
    

    【讨论】:

    • 还有一个问题。与其返回整行,不如只返回字段“TDATE”
    • @Tony - 将选择更改为select c.TDATE。你也可以tblTrans.Max(c => c.TDATE)。 (别忘了接受我的回答。;-))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 2019-05-22
    • 2017-10-02
    • 2014-03-10
    • 1970-01-01
    相关资源
    最近更新 更多