Hi, I am trying to string together a number of SqlExpressions. The code below is generating the correct SQL when I look at the conn.GetLastSql() - and when I execute it on the server, it returns the number of rows I would expect, but the code below is returning zero Occupancy objects.
I can of course do this via untyped, but would rather keep the compile-time checking. Any ideas?
G
var dateExp = conn.From<Occupancy>();
//start before window but end within window
dateExp.Or(d => d.StartDate < request.StartDate && d.EndDate > request.StartDate && d.EndDate < request.EndDate);
//start before window and end after window
dateExp.Or(d => d.StartDate < request.StartDate && d.EndDate > request.EndDate);
//start within window and end after window
dateExp.Or(d => d.StartDate > request.StartDate && d.EndDate > request.EndDate);
//start and end within window
dateExp.Or(d => d.StartDate > request.StartDate && d.EndDate < request.EndDate);
//start date before end date and no end date
dateExp.Or(d => d.StartDate < request.EndDate && d.EndDate == null);
var dateoccupancies = conn.Select(dateExp);
The SQL this is generating is below. This returns 7 rows when executed.
SELECT "OccupancyId", "OccupancyTypeId", "MooringId", "AccountId", "BoatId", "MooringReleaseId", "StartDate", "EndDate", "OrderId", "Notes", "CreatedOn", "ModifiedOn", "CreatedBy", "ModifiedBy", "Deleted"
FROM "Occupancy"
WHERE ((("StartDate" < N'20160401 01:00:00.000') AND ("EndDate" > N'20160401 01:00:00.000')) AND ("EndDate" < N'20160501 01:00:00.000')) OR (("StartDate" < N'20160401 01:00:00.000') AND ("EndDate" > N'20160501 01:00:00.000')) OR (("StartDate" > N'20160401 01:00:00.000') AND ("EndDate" > N'20160501 01:00:00.000')) OR (("StartDate" > N'20160401 01:00:00.000') AND ("EndDate" < N'20160501 01:00:00.000')) OR (("StartDate" < N'20160501 01:00:00.000') AND ("EndDate" is null))