Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: entity EF
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 8:42am
Edited 9-Feb-12 8: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
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100