linq to sql select as command

linq to sql select as command

I have a SQL query similar to this:

SELECT 
((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.

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); 
.
.
.
.