I have following expression
var list = techlinks.GetItems().Where(p => p.Status == 1).ToList();
I want to change this so that I want to select the earliest date value for example
var list = techlinks.GetItems().Where(p =>p.Date is earliest && p.Status == 1).ToList();
Please let me know what to insert for p.Date is earliest
Thanks
Here's another way.
var list=techlinks.GetItems()
.Where(p=> p.Status==1)
.Min(d => d.Date)
.Single();
you can use OrderBy
or OrderByDescending()
to sort them on Date this way:
var list = techlinks.GetItems()
.Where(p => p.Status == 1)
.OrderBy(x=>x.Date).First(); // this will give oldest date
and:
var list = techlinks.GetItems()
.Where(p => p.Status == 1)
.OrderByDescending(x=>x.Date).First(); // this will give latest date
Student student = _context.Set<Student>()
.Where(p => p.StudentID == ID.Value)
.OrderBy(p => p.AddedDate)
.FirstOrDefault();
If there might be multiple items all with the earliest date:
var list = techlinks.GetItems()
.Where(p => p.Status == 1)
.OrderBy(x=>x.Date)
.GroupBy(x => x.Date)
.First()
.ToList()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With