Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: entityEF
How to write below condition in EF 3.5 Query. Below in SQL format.
 
a.member in ('Free','PartTime') and (DATEDIFF(m,asofdate,getdate())>0 or AsOfDate is null)
Posted 9-Feb-12 7:42am
Edited 9-Feb-12 7:43am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It's LINQ you are using. use DateTime.Now to get the current date, and then compare it from there. Do you know how to write LINQ queries ?
  Permalink  
Comments
divesh12 at 9-Feb-12 13:57pm
   
var team = from a in Entity.Report.Where(a=> a.Active == true) select a; This is my Query want to add in this query. Can you please add for me.
divesh12 at 9-Feb-12 13:58pm
   
a.member in ('Free','PartTime') and (DATEDIFF(m,asofdate,getdate())>0 or AsOfDate is null) Please add this in LINQ format in where statement.
Christian Graus at 9-Feb-12 13:59pm
   
var team = from a in Entity.Report.Where(a=> a.Active == true && (a.member == "Free" || a.Member == "PartTime") && (a.AsOfDate == null || a.AsOfDate > DateTime.Now) That is an absolute wild guess.
divesh12 at 13-Feb-12 8:07am
   
var team = from a in Entity.Report where ( (a.Active == true) && (a.Member == "Free" || a.Member == "PartTime") && (a.AsOfDate > DateTime>now || a.AsOfDate == null))
divesh12 at 13-Feb-12 8:07am
   
Thanks Christian
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Have a look at http://www.linqpad.net/[^]
 
LINQPad lets you interactively query databases using linq - it's a useful tool for trying out queries.
 
I'm also pretty certain that I would use ExecuteStoreQuery[^] and just execute the query using your SQL.
 
I expect that you know that your query will be translated back to SQL because SQL server hasn't got a clue about linq.
 
Best regards
Espen Harlinn
  Permalink  
Comments
thatraja at 11-Feb-12 9:58am
   
5!
Espen Harlinn at 11-Feb-12 10:13am
   
Thank you, thatraja :)

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 457
1 OriginalGriff 430
2 Shai Vashdi 240
3 Emre Ataseven 165
4 Peter Leow 146
0 Sergey Alexandrovich Kryukov 8,944
1 OriginalGriff 5,280
2 Peter Leow 3,985
3 Maciej Los 3,535
4 Abhinav S 3,218


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 9 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid