I am doing a final project in a C# class where I have to build a Hotel Management system, but I am currently stuck on checking if a room is already booked between two dates. I have tried to figure it out on my own, but I do not know how to convert this query string into LINQ.
Any help?
query = "SELECT * FROM Suites WHERE SuiteType = " + suitetype + " AND NumberOfAdultsAllowed >= " + adults + " AND NumberOfChildrenAllowed >= " + children + " AND ";
query += "Suites.SuiteNumber NOT IN (SELECT SuiteNumber FROM Bookings WHERE ";
query += "(StartDate BETWEEN @_start AND @_end) OR ";
query += "(EndDate BETWEEN @_start AND @_end) OR ";
query += "(@_start BETWEEN StartDate and EndDate) OR ";
query += "(@_end BETWEEN StartDate and EndDate) OR ";
query += "(@_start <= StartDate and @_end >= EndDate) OR ";
query += "(@_start >= @_end))";
I thought of first getting all rooms by
var querySearch = from q in db.Suites
where q.SuiteType == suitetype
select q;
and then checking it against another query that checks if suite number is in table Bookings and if it is between the dates specified.
But I get lost everytime.