Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
SQL
select dayofweek, application, SystemOutageFrom,
Case when (DateDiff(hour, b.SystemOutageFrom, b.SystemOutageTo) < 0) then DateAdd(day, 1, b.SystemOutageTo)
else b.SystemOutageTo end as SystemOutageTo from (
select dayofweek, application, DateAdd(day, (dayofweek + 1 - DATEPART(weekday, GetDate())), 
(Cast (SystemOutageFrom as datetime) + CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME))) as SystemOutageFrom,
DateAdd(day, (dayofweek + 1 - DATEPART(weekday, GetDate())),
(Cast (SystemOutageTo as datetime) + CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)) ) as SystemOutageTo
from weeklyoutage ) b  order by dayofweek, b.SystemOutageFrom



My question is how do I put this complex query in Linq? Any ideas to start will be helpful.
Posted
Updated 23-Jul-13 6:33am
v5
Comments
joshrduncan2012 23-Jul-13 12:30pm    
What's your question?
ZurdoDev 23-Jul-13 12:39pm    
Have you learned LINQ at all?
TryAndSucceed 23-Jul-13 12:42pm    
I am a beginner and mostly have been working on the Linq queries to just retrieve data but not manipulation in the queries. I have searched for this and there are ways that is SQLMethods.DateDiffHour for getting difference in hours,but I am confused in placing them around in query.

You can try http://www.sqltolinq.com/. I don't have your database so I can not test it but you can download the trial for 10 days and test it.
 
Share this answer
 
Comments
TryAndSucceed 23-Jul-13 15:20pm    
It helped a bit as it says that Floor and DateDiff are not supported by Linq to convert.
[no name] 23-Jul-13 18:39pm    
@Faraaz Habeeb - well that just means that you will need to find a different way to do it try looking up "LINQ equivalent to SQL Floor" and "LINQ equivalent to SQL DateDiff"
Can you please give detailed question ,table names and all that so i can help you
 
Share this answer
 
Comments
Sushil Mate 26-Jul-13 1:40am    
wrong place, use comment/question section widget.
RomilGandhi 26-Jul-13 1:44am    
ok thanx
TryAndSucceed 31-Jul-13 11:43am    
Thanks Romil. I found solution. I created a separate method to do what it was doing in the query.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900