Logo Questions Linux Laravel Mysql Ubuntu Git Menu

linq to sql select as command

I have a SQL query similar to this:

((dbo.ActiveWO.StartTime*60*60*24) - dbo.ActiveWOUpdatedTimes.ElapsedTime) as TimeLeft

How can I insert that into a linq to sql query?

Basically not sure what the syntax is for AS and how to actually write the calculation above in c# query and then I need to orderby TimeLeft.

like image 245
sd_dracula Avatar asked Mar 25 '23 03:03


1 Answers

From your previous question, I guess you have a query like, below. You can use select new to create an anonymous type object and then use OrderBy like:

var query = (from activeWO in context.ActiveWOs
            join activeWOUpdated in context.ActiveWOUpdatedTimes on activeWO.PW_ID equals activeWOUpdated.PW_ID into dj
            from activeWOUpdated in dj.DefaultIfEmpty()
            where activeWO.WODC.Contains("IDC")
            select new 
              TimeLeft = activeWO.StartTime * 60 * 60 * 24 - dj.ElapsedTime
            }).Orderby(r=> r.TimeLeft); 
like image 173
Habib Avatar answered Apr 01 '23 02:04