sql server - Why my Linqued query is not giving me proper result? -


i have sql query gives me proper result i.e names of employee sorted z using order clause

select distinct(empntlogin),employee attendance   createdate>='2016-01-01' order empntlogin 

when converted same query in linq,i getting right result order clause not working. here linqued query

    var query = (from attendance in db.attendances                      orderby attendance.empntlogin                      attendance.createdate.value.year >= 2016                      select new { attendance.employee, attendance.empntlogin }).distinct(); 

in linq query, distinct applied after orderby , therefore order discarded.

apply orderby after call distinct

var query = (from attendance in db.attendances              attendance.createdate.value.year >= 2016              select new              {                  attendance.employee,                  attendance.empntlogin              }).distinct().orderby(att => att.empntlogin); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -