コード例 #1
0
 public async Task <IEnumerable <BookingRange> > GetConflictingSlots(
     Guid roomId,
     DateTimeOffset start,
     DateTimeOffset end)
 {
     return(await _context.Bookings
            .Where(b => b.Room.Id == roomId && _dateLogicService.DoesConflict(b, start, end))
            // Split each existing booking up into a set of atomic slots
            .SelectMany(existing => _dateLogicService.GetAllSlots(existing.StartAt, existing.EndAt))
            .ToArrayAsync());
 }
コード例 #2
0
        public async Task <IEnumerable <BookingRange> > GetConflictingSlots(
            Guid roomId,
            DateTimeOffset start,
            DateTimeOffset end)
        {
            var bookings = _context.Bookings.ToList()
                           .Where(b => b.Room.Id == roomId && _dateLogicService.DoesConflict(b, start, end)).ToList();

            var goodOnes = bookings
                           // Split each existing booking up into a set of atomic slots
                           .SelectMany(existing => _dateLogicService
                                       .GetAllSlots(existing.StartAt, existing.EndAt)).ToList();

            return(goodOnes);
        }
コード例 #3
0
        /// <summary>
        ///
        /// "entity framework translates the linw expression in to sql query, so that it can execuete the whole thing on databse/server , instead of fetching the whole data to client side"
        ///
        /// 'new System.Linq.SystemCore_EnumerableDebugView<RestApi.Models.BookingEntity>(k).Items' threw an exception of type 'System.InvalidOperationException'
        ///
        ///
        ///
        ///     The LINQ expression 'DbSet<BookingEntity>
        /// .LeftJoin(
        ///     outer: DbSet<RoomEntity>,
        ///     inner: b => EF.Property<Nullable<Guid>>(b, "RoomId"),
        ///     outerKeySelector: r => EF.Property<Nullable<Guid>>(r, "Id"),
        ///     innerKeySelector: (o, i) => new TransparentIdentifier<BookingEntity, RoomEntity>(
        ///         Outer = o,
        ///         Inner = i
        ///     ))
        /// .Where(b => b.Inner.Id == __roomid_0 && ___dateLogicService_1.DoesConflict(
        ///     b: b.Outer,
        ///     start: __start_2,
        ///     end: __end_3))' could not be translated. Either rewrite the query in a form that can be translated,
        ///     or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().
        ///     See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
        ///
        /// The above is failing because it is not supported in .net core 3.0 and above
        ///
        /// </summary>
        /// <param name="roomid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public async Task <IEnumerable <BookingRange> > GetConflictingSlots(
            Guid roomid,
            DateTimeOffset start,
            DateTimeOffset end)
        {
            //https://docs.microsoft.com/en-us/ef/core/querying/client-eval
            //https://stackoverflow.com/questions/1578778/using-iqueryable-with-linq
            var result = _context.Bookings.Where(b => (b.Room.Id == roomid)).AsEnumerable().Where(b => _dateLogicService.DoesConflict(b, start, end)).SelectMany(existing => _dateLogicService
                                                                                                                                                                 .GetAllSlots(existing.StartAt, existing.EndAt));

            //_dateLogicService.DoesConflict(b, start, end))).Select(x=>x);

            /*var l = k
             *
             * .SelectMany(existing => _dateLogicService
             *   .GetAllSlots(existing.StartAt, existing.EndAt));*/
            //.ToArrayAsync();

            // return await Task.FromResult(l.ToArray());

            return(await Task.FromResult(result.ToArray()));
        }