c# - Get Row with Min Date in LINQ? -


i've got table date/time in , i'd find entire row minimum date. see example:

id     first     last     adatetime             processed 1      joe       smith    09/06/2013 04:00   true 1      joe       smith    09/06/2013 02:00   false 2      jack      jones             3      john      jack     09/05/2013 06:00   true 3      john      jack     09/26/2013 02:00   false 

what want query following:

id     first     last     adatetime             processed 1      joe       smith    09/06/2013 02:00   false 2      jack      jones             3      john      jack     09/05/2013 06:00   true 

i have linq statement comes close:

        var uniqueguys = d in tests.asenumerable()                          group d d.id g                          let f = g.firstordefault()                          f != null                          select new                          {                              f.id,                              f.first,                              f.last,                              adatetime = g.min(c => c.datetime),                              f.processed                          }; 

this gives me each of 3 ids minimum date correctly, rest of information incorrect. example, id 1, joe smith having date of 09/06/201 2:00 am, right, shows processed true instead of false that's attached row. looks grabs minimum date/time first record can find other stuff. there way full row minimum adatetime?

you can orderby , select first.

as in:

var uniqueguys = d in d in tests.asenumerable()                  group d d.id g                  select g.orderby(p => p.datetime).first();  

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -