-2

I have a StayDormApplications table , I have a SQL as below ,

var systemFilesItem = _db.StayDormApplications.Single(r => r.Id == dormapplication.Id);
string SQL = "SELECT  sum(days) days from StayDormApplications where poster = '" + LoginAccount + "' and DATEPART(MONTH, Sdate) = '"+ month_name + "' group by DATEPART(MONTH, Sdate);"; // 

how to convert the SQL with (c#) LINQ?

georgetovrea
  • 537
  • 1
  • 8
  • 28

1 Answers1

0

You can try to use SqlFunctions.DatePart to make it, otherwise, your query seems don't need to use group by becuase you filter it on the condition.

var systemFilesItem = _db.StayDormApplications
                          .Where(x=> x.poster == LoginAccount && SqlFunctions.DatePart("MONTH", x.Sdate).Value == month_name)
                          .Sum(x=> x.days);
D-Shih
  • 44,943
  • 6
  • 31
  • 51