Question: How do you get a recent record using EF Core C# Query? I would like to retrieve a most recent data record from the database but the query returns the last record. How does this work?
Please Login to see the rest of the answer
Answer: If you want to get the most recent record from the database using EF Core or Entity Framework then you must order the result then get FirstOrDefault() record from the dataset returned. See the code below:
var MyRecentRecord = _context.MyDataModalOrPOCO.Where(a => a.MyLovelyPredicateHere).OrderByDescending(b=>b.MyLovelyPropertyNameHere).FirstOrDefault(); //This will retrieve the most recent data node from the database. :) Good Luck!!