I have found a solution to my problem. I compare the TimeSlotId using Intersect
, if there are intersection, it then return true.
public bool BookingExist(Booking booking)
{
var resultContext = context.Bookings
.Where(b => b.Room.Id == booking.RoomId && b.BookDate == booking.BookDate)
.SelectMany(b => b.TimeSlots.Select(bt => bt.TimeSlotId))
.AsEnumerable();
var resultInput = booking.TimeSlots.Select(bt => bt.TimeSlotId);
if (resultContext.Intersect(resultInput).Count() > 0)
return true;
else
return false;
}
CLICK HERE to find out more related problems solutions.