Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

LINQ Select all records by MAX data syntax help

Hello all,

I have a table CustomerAccount that has a field called TransactionDate that is loaded to with the same transaction date about 3k records a day.   I need to get all the records from this table where the TransactionDate is the latest date.   I also need to make sure performance is optimal.   What is the best way to do this?   I also have the same for another table but that table does not have an identity column.  So for example for the Customer table I came up with this:

  var customers = from n in GetList<CustomerModel>()
                                group n by n.CustomerID into g
                                select g.OrderByDescending(t => t.TransactionDate).FirstOrDefault();

I also don't know if that is optimal either.   If that is fine I will use that but also have the other table without an identity so wondering if I should do something different.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial