How to find employee by ID in LINQ -
how find employee id , group 2 max , min time in id=1 , date="2017-05-01" same row using linq.
list<bllcls> obj = new list<bllcls>(); obj.add(new bllcls { id =1 , date = convert.todatetime("2017-05-01"),time="08:00:00" }); obj.add(new bllcls { id =1 , date = convert.todatetime("2017-05-01"),time="19:00:00" }); obj.add(new bllcls { id =2 , date = convert.todatetime("2017-05-01"),time="08:00:00" }); obj.add(new bllcls { id =2 , date = convert.todatetime("2017-05-01"),time="19:00:00" });
from (id=1)
how to?
i need in format
row 1 = id , date , min time , max time col = 1 , 2017-05-01, 08:00:00 , 19:00:00 row 2 = id , date , min time , max time col = 2 ,2017-05-01, 08:00:00 , 19:00:00
groupby
friend:
var query = obj.groupby(x => x.id) .select(grp => new { id = grp.key, mindate = grp.min(x => x.date), maxdate = grp.max(x => x.date) });
if want specified id
use where
:
var id1query = query.where(x => x.id == 1);
if expect 1 use firstordefault
or singleordefault
:
var id1 = query.firstordefault(x => x.id == 1);
Comments
Post a Comment