Click here to Skip to main content
12,957,398 members (61,006 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
Updated 9-Feb-12 7:43am
Wendelius349.3K
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 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 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 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 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 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 11-Feb-12 9:58am
   
5!
Espen Harlinn 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,994
CHill60 3,550
Maciej Los 3,312
ppolymorphe 2,170
Jochen Arndt 1,973


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 9 Feb 2012
Copyright © CodeProject, 1999-2017
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