I have a table and I need to select the record based on an Id. I only want to return the record that has the Max(Date) on a date field. How do I do that?
In SQL Server I use this
SELECT * FROM dch
WHERE EffectiveDate = (SELECT MAX(EffectiveDate) FROM dch
WHERE ID = 99) AND ID = 99
How can I do this in Linq. Unfortunately this app is coded in VB.NET as we inherited it that way.
I was trying these
Dim qry = (From dch In db.dch _
Where dch.Dealer.Equals(Dealer) _
Select dch.EffectiveDate).Max()
or
Dim qry = (From dch In db.dch _
Where dch.Dealer.Equals(Dealer) _
Select ).Max(dch.EffectiveDate)
And obviously they do not work. Am I even close? Any ideas would be appreciated.
Thanks In Advance, Chris in San Diego