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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With