❔ Getting the last data registration time for multiple locations
I have the following Sql table, which I access using ef core.
I need to find the last registration date for each different location. Currenetly I do the following:
This is obviously not great. What would be the propper way to do this?
7 Replies
Something like that, maybe?
Yeah, that sounds like a way more resonable approach. Thanks!
what is the difference between using orderByDec().First over Max() in this case?
Max()
uses the default comparator of the object
Unless you have one such comparator implemented, it won't work
OrderByDescending()
meanwhile lets you order by a given property of the objectBut all SQL types have a comparor right?
so OrderBy(x=>x.prop) and Max(x=>x.prop) would both point to a base sql type
Ah, I thought you meant using
Max()
without anything passed to it
Yeah, .OrderByDescending(x => x.Prop).First()
and .Max(x => x.Prop)
should work the same, then
Or, rather, .MaxBy(x => x.Prop)
Since I don't think .Max()
takes a predicatesorry for being unprecise and thanks a lot for explaining.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.