I need to display an notification based on the date it was posted on the DB table. Right now I am using the below logic:
context.Messages.FirstOrDefaultAsync(e => e.StartDate <= DateExtensions.Now && e.EndDate >= DateExtensions.Now)
This would return the value properly, however, if I post another message with same date and time, I should get that, but my code still displays the older message. Please help me here?
CodePudding user response:
you need to order the messages somehow, e.g:
context.Messages.OrderByDescending(e => e. Id)
. FirstOrDefaultAsync(e => e.StartDate <= DateExtensions.Now && e.EndDate >= DateExtensions.Now)
