开发者

Get the record (row) in a table with the most recent (greatest date) LINQ to SQL C#

开发者 https://www.devze.com 2023-04-03 07:16 出处:网络
I have a table called tblTrans it has 4 fields: ID, CustID, TDATE, Name How can in in LINQ to SQL CE, get the newest or most recent row.I want the query to return all 开发者_如何学编程the fields for

I have a table called tblTrans it has 4 fields: ID, CustID, TDATE, Name

How can in in LINQ to SQL CE, get the newest or most recent row. I want the query to return all 开发者_如何学编程the fields for this row. I was trying this and could not get it to work:

tblTrans retTrans = (from c by c.TDATE into g orderby c.TDATE)


Try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消