This is my query :
var model = (from p in entity.vehicule
join y in entity.indisponible on p.Matv equals y.idv
where p.agence.idgov == idv && (!(dd1 >= y.Dd && dd1 <= y.Df) || !(df1 >= y.Dd && df1 <= y.Df))
select p).ToList();
I have tried with many ways to write this part :
(!(dd1 >= y.Dd && dd1 <= y.Df) || !(df1 >= y.Dd && df1 <= y.Df))
In this way(this is how it has to be look in sql):
(dd1 Not Between Date(y.dd) And Date(y.dF)) OR (df1 Not Between Date(y.dd) And Date(y.df))
dd1 is date (From), Df1 is date (to).
I think I’m missing something here 🙁
Edit 2: After many comments, hopefully this is the result you’re after
Edit 1
If we alter it slightly so instead of checking against a birthday, we’ll check against
favourite days. Not let us assume that a person can have multiple favourite days, and that we want to select everyone that doesn’t have a favourite day, that is within 2 days. Let’s write out our assumptions further:Richard‘s favourite days are,5 May 2012and10 September 2012Amy‘s favourite days are,8 August 2012and12 December 2012Matthews‘ favourite days is,30 October 2012And let us say we want to find everyone who doesn’t have a favourite day between
1 May 2012and1 September 2012; our result output should only beMatthew, we could write:What the above statement is saying, is we want to select all people, but only if
noneof their favourite dates are between two dates.Alternatively we could say, lets select a person, if they do have a date outside of a range. So assuming we wanted to check from
1 May 2012to1 November 2012, so our result set was nowRichardandAmy, this could be achieved like so:Original
I found it tricky to read your abbreviated variables, so I hope you don’t mind but I thought I’d write a quick demo how to do a “not between” two dates.
I think you’re on the right lines with things. Here are a couple of ways you could approach it. The following methods do the same thing, but one checks the inverse.