public async Task AssociateProjectAndCategory(AssociationRequest associationRequest)
        {
            Category category = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(context.Categories, c => c.Type == associationRequest.CategoryType &&
                                                                                             c.Name == associationRequest.CategoryName);

            if (category == null)
            {
                category = new Category()
                {
                    Type = associationRequest.CategoryType, Name = associationRequest.CategoryName
                };
                context.Categories.Add(category);
                await context.SaveChangesAsync();
            }

            Project project = await GetProjectAsync(associationRequest.ProjectID);

            ProjectCategory pc = new ProjectCategory()
            {
                Project = project, Category = category
            };

            context.ProjectCategories.Add(pc);
            await context.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task <KillLogResult> AddKill(string playerName, string userUsername, int power, string imageLink)
        {
            var normalizedPlayerName = playerName.Normalise();
            var normalizedUsername   = userUsername.Normalise();

            var player = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(_db.Players, x => x.NormalizedName == normalizedPlayerName);

            if (player == null)
            {
                return(KillLogResult.CannotFindPlayer);
            }

            _db.Kills.Add(new Kill
            {
                KilledBy           = userUsername,
                KilledByNormalised = normalizedUsername,
                Player             = player,
                KilledOn           = DateTime.Now,
                Power     = power,
                ImageLink = imageLink
            });

            await _db.SaveChangesAsync();

            return(KillLogResult.OK);
        }
Beispiel #3
0
        public async Task <TResult> FetchAsync <TResult>(Expression <Func <TEntity, TResult> > selector, Expression <Func <TEntity, bool> > whereExpression, Expression <Func <TEntity, object> > orderByExpression = null, bool ascending = false, bool writeDb = false, bool noTracking = true, CancellationToken cancellationToken = default)
        {
            TResult result;

            var query = this.GetDbSet(writeDb, noTracking).Where(whereExpression);

            if (orderByExpression == null)
            {
                result = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query.OrderByDescending(x => x.Id).Select(selector), cancellationToken);
            }
            else
            {
                result = ascending
                          ? await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query.OrderBy(orderByExpression).Select(selector), cancellationToken)
                          : await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query.OrderByDescending(orderByExpression).Select(selector), cancellationToken)
                ;
            }

            return(result);

            //dynamic result;
            //if (result == null)
            //    return null;

            //return (typeof(TEntity) == typeof(TResult))
            //    ? result as TEntity
            //    : JsonSerializer.Deserialize<TEntity>(JsonSerializer.Serialize(result));
            //;
        }
Beispiel #4
0
        public async Task <TEntity> FindAsync(Expression <Func <TEntity, bool> > whereExpression, Expression <Func <TEntity, dynamic> > navigationPropertyPath = null, Expression <Func <TEntity, object> > orderByExpression = null, bool ascending = false, bool writeDb = false, bool noTracking = true, CancellationToken cancellationToken = default)
        {
            TEntity result;

            var query = this.GetDbSet(writeDb, noTracking).Where(whereExpression);

            if (navigationPropertyPath != null)
            {
                query = EntityFrameworkQueryableExtensions.Include(query, navigationPropertyPath);
            }

            if (orderByExpression == null)
            {
                result = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query.OrderByDescending(x => x.Id), cancellationToken);
            }
            else
            {
                result = ascending
                          ? await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query.OrderBy(orderByExpression), cancellationToken)
                          : await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query.OrderByDescending(orderByExpression), cancellationToken)
                ;
            }

            return(result);
        }
 public static Task <TSource> FirstOrDefaultEFCoreAsync <TSource>(
     this IQueryable <TSource> source,
     Expression <Func <TSource, bool> > predicate,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(
                source, predicate, cancellationToken));
 }
Beispiel #6
0
        public static async Task <T> FirstOrDefaultAsync <T>(this IEnumerable <T> list)
        {
            if (list is IQueryable <T> query)
            {
                return(await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query));
            }

            return(list.FirstOrDefault());
        }
Beispiel #7
0
 public async Task <decimal> GetCurrentPrice(long itemId, CancellationToken cts = new CancellationToken())
 {
     return(await Task.Run(() =>
     {
         cts.ThrowIfCancellationRequested();
         return EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(
             Db.MovmentGoodTypes.Select(p => AutomationAccountingGoodsContext.GetCurrentPrice(itemId)), cts);
     }, cts));
 }
        public static async Task <TSource> FirstOrDefaultAsync <TSource>(this IQueryable <TSource> source, Expression <Func <TSource, bool> > predicate = null)
            where TSource : Entity
        {
            if (predicate != null)
            {
                return(await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(source, predicate));
            }

            return(await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(source));
        }
Beispiel #9
0
        public async Task <IActionResult> EditPart(int id)
        {
            var query = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync((from ct in _context.Contacts
                                                                                      //join ca in _context.ContactToAddress on ct.ID equals ca.ContactId
                                                                                      join a in _context.Addresses on ct.ID equals a.ContactID
                                                                                      where ct.ID == id && a.Name.Contains("Home")
                                                                                      select a));

            //   return View("EditPart", contacts);
            return(PartialView("TestView", query));
        }
Beispiel #10
0
        public async Task <Result <PlaceDTO> > GetPlaceAsync(int id)
        {
            Result <PlaceDTO> res   = new Result <PlaceDTO>();
            Place             place = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync <Place>(_unitOfWork.EntityRepository <Place>().GetQueryable((Place w) => w.IsDeleted == false && w.Id == id, null), default(CancellationToken));

            if (place == null)
            {
                return(res.Fail("Place yok!"));
            }
            PlaceDTO dataVal = Mapper.Map <Place, PlaceDTO>(place);

            return(res.Success(dataVal));
        }
Beispiel #11
0
        public async Task <TEntity> GetAsync(long keyValue, Expression <Func <TEntity, dynamic> > navigationPropertyPath = null, bool writeDb = false, CancellationToken cancellationToken = default)
        {
            var query = this.GetDbSet(writeDb, false).Where(t => t.Id == keyValue);

            if (navigationPropertyPath != null)
            {
                return(await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(EntityFrameworkQueryableExtensions.Include(query, navigationPropertyPath), cancellationToken));
            }
            else
            {
                return(await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query, cancellationToken));
            }
        }
Beispiel #12
0
        public async Task <Result <PanelUserDTO> > GetUserAsync(string email, string password)
        {
            Result <PanelUserDTO> res = new Result <PanelUserDTO>();
            string    hashedPassword  = PasswordHelper.MD5Hash(password);
            PanelUser panelUser       = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync <PanelUser>((IQueryable <PanelUser>) EntityFrameworkQueryableExtensions.Include <PanelUser, Company>(_unitOfWork.EntityRepository <PanelUser>().GetQueryable((PanelUser w) => w.IsDeleted == false && w.Email == email && w.Password == hashedPassword && !w.IsDeleted, null), (Expression <Func <PanelUser, Company> >)((PanelUser w) => w.Company)), default(CancellationToken));

            if (panelUser == null)
            {
                return(res.Fail("User yok!"));
            }
            PanelUserDTO dataVal = Mapper.Map <PanelUser, PanelUserDTO>(panelUser);

            return(res.Success(dataVal));
        }
Beispiel #13
0
        public async Task <TEntity> GetAsync(long keyValue, IEnumerable <Expression <Func <TEntity, dynamic> > > navigationPropertyPaths = null, bool writeDb = false, CancellationToken cancellationToken = default)
        {
            if (navigationPropertyPaths == null || navigationPropertyPaths.Count() <= 1)
            {
                return(await this.GetAsync(keyValue, navigationPropertyPaths.FirstOrDefault(), writeDb, cancellationToken));
            }

            var query = this.GetDbSet(writeDb, false).Where(t => t.Id == keyValue);

            foreach (var navigationPath in navigationPropertyPaths)
            {
                query = EntityFrameworkQueryableExtensions.Include(query, navigationPath);
            }
            return(await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query, cancellationToken));
        }
        public async Task <T> FirstOrDefaultAsync()
        {
            var list = await GetStaticDataAsync(async x => (T)await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync((dynamic)x));

            list.RemoveAll(x => x == null);
            var q = list.AsQueryable();

            var(sortColumn, sortType) = _source.GetOrderBy();
            if (!sortColumn.IsNullOrEmpty())
            {
                q = q.OrderBy($"{sortColumn} {sortType}");
            }

            return(q.FirstOrDefault());
        }
        public async Task <TEntity> FirstOrDefaultAsync(Expression <Func <TEntity, bool> > predicate,
                                                        params Expression <Func <TEntity, object> >[] includes)
        {
            IQueryable <TEntity> query = Context.Set <TEntity>().AsQueryable <TEntity>();

            Expression <Func <TEntity, object> >[] expressionArray = includes;
            for (int index = 0; index < expressionArray.Length; ++index)
            {
                Expression <Func <TEntity, object> > include = expressionArray[index];
                query = (IQueryable <TEntity>)EntityFrameworkQueryableExtensions.Include <TEntity>(
                    (IQueryable <TEntity>)query, include.AsPath());
            }

            return(await(Task <TEntity>) EntityFrameworkQueryableExtensions.FirstOrDefaultAsync <TEntity>(
                       (IQueryable <TEntity>)query, predicate, new CancellationToken()));
        }
        // GET: Categories/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var category = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(context.Categories, m => m.Id == id);

            if (category == null)
            {
                return(NotFound());
            }

            return(View(category));
        }
Beispiel #17
0
    public async Task <Team> AddAsync(Team team)
    {
        var existingEvent = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(context.Events, c => c.ID == team.EventID);

        var newTeam = team.WithEventId(existingEvent.ID);
        var dbTeam  = mapper.Map <DbTeam>(newTeam);

        await context.Teams.AddAsync(dbTeam);

        existingEvent.Teams.Add(dbTeam);

        context.Update(existingEvent);

        await context.SaveChangesAsync();

        return(mapper.Map <Team>(dbTeam));
    }
Beispiel #18
0
    public async Task <Result> UsedPromotionAsync(int id)
    {
        DateTime  today = DateTime.Today;
        Promotion item  = await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync <Promotion>((IQueryable <Promotion>) EntityFrameworkQueryableExtensions.Include <Promotion, User>((IQueryable <Promotion>)EntityFrameworkQueryableExtensions.Include <Promotion, Place>(_unitOfWork.EntityRepository <Promotion>().GetQueryable((Expression <Func <Promotion, bool> >)((Promotion w) => w.Id == id && w.IsActive && w.DueDate >= today), (Func <IQueryable <Promotion>, IOrderedQueryable <Promotion> >)null, Array.Empty <Expression <Func <Promotion, object> > >()), (Expression <Func <Promotion, Place> >)((Promotion i) => i.Place)), (Expression <Func <Promotion, User> >)((Promotion i) => i.User)), default(CancellationToken));

        if (item == null)
        {
            return(Result.Fail("Aktif promosyon tanımı bulunamadı!", (Exception)null, (string)null));
        }
        item.IsActive = false;
        await _unitOfWork.SaveChangesAsync();

        await _emailSender.Send((IEnumerable <string>) new string[1]
        {
            item.User.Email
        }, "Hesabınızdaki promosyon kullanıldı!", item.Place.Name + " mekanındandaki tanımlu promosyonunuzu kullandınız. <br/> Promosyon: " + item.Message);

        return(Result.Success("Başarılı"));
    }
Beispiel #19
0
        public Task <Spawnpoints> GetNearestSpawnpointAsync(double latitude, double longitude)
        {
            return(EntityFrameworkQueryableExtensions.FirstOrDefaultAsync <Spawnpoints>(Spawnpoints.FromSql($@"
SELECT * FROM spawnpoints
 WHERE id IN 
 (
  SELECT id FROM
  (
   SELECT id, despawn_time, IFNULL(duration, 30), lat, lon, 111.045 * DEGREES(ACOS(COS(RADIANS({latitude}))
   * COS(RADIANS(lat))
   * COS(RADIANS(lon) - RADIANS({longitude}))
   + SIN(RADIANS({latitude}))
   * SIN(RADIANS(lat)))) 
   AS distance_in_km
   FROM spawnpoints
   ORDER BY distance_in_km ASC
  ) AS temp WHERE distance_in_km < 0.1
 )
 LIMIT 0,1")));
        }
        public async Task <bool?> Handle(ChosenInlineResult data, object context = default, CancellationToken cancellationToken = default)
        {
            var resultParts = data.ResultId.Split(':');

            switch (resultParts[0])
            {
            case PREFIX:
                if (myTimeZoneNotifyService.DecodeId(resultParts.Skip(1).FirstOrDefault(), out var chatId, out var messageId) &&
                    resultParts.Skip(2).FirstOrDefault() is {} timeZoneId&& myDateTimeZoneProvider.GetZoneOrNull(timeZoneId) is {})
                {
                    if (!await CheckRights(chatId, data.From, cancellationToken))
                    {
                        await myBot.EditMessageTextAsync(data.InlineMessageId !, new InputTextMessageContent("You have no rights"), cancellationToken : cancellationToken);

                        return(false);
                    }

                    var settings = myDB.Set <TimeZoneSettings>();
                    if (await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(settings.Where(s => s.ChatId == chatId && s.TimeZone == timeZoneId), cancellationToken) == null)
                    {
                        settings.Add(new TimeZoneSettings {
                            ChatId = chatId, TimeZone = timeZoneId
                        });
                        await myDB.SaveChangesAsync(cancellationToken);
                    }

                    var(content, replyMarkup) = await myTimeZoneNotifyService.GetSettingsMessage(new Chat { Id = chatId, Type = ChatType.Sender }, cancellationToken : cancellationToken);

                    await myBot.EditMessageTextAsync(data.InlineMessageId !, content, replyMarkup, cancellationToken);

                    if (messageId != 0)
                    {
                        await myBot.DeleteMessageAsync(chatId, messageId, cancellationToken);
                    }

                    return(true);
                }
                break;
            }
Beispiel #21
0
 public Task <TSource> FirstOrDefaultAsync <TSource>(IQueryable <TSource> source, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(source, cancellationToken));
 }
        public async Task Extension_methods_validate_arguments()
        {
            // ReSharper disable AssignNullToNotNullAttribute

            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.FirstAsync <int>(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.FirstAsync <int>(null, s => true));
            await ArgumentNullTest("predicate", () => Source().FirstAsync(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.FirstOrDefaultAsync <int>(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.FirstOrDefaultAsync <int>(null, s => true));
            await ArgumentNullTest("predicate", () => Source().FirstOrDefaultAsync(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.SingleAsync <int>(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.SingleAsync <int>(null, s => true));
            await ArgumentNullTest("predicate", () => Source().SingleAsync(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.SingleOrDefaultAsync <int>(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.SingleOrDefaultAsync <int>(null, s => true));
            await ArgumentNullTest("predicate", () => Source().SingleOrDefaultAsync(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.ContainsAsync(null, 1));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.ContainsAsync(null, 1, new CancellationToken()));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.AnyAsync <int>(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.AnyAsync <int>(null, s => true));
            await ArgumentNullTest("predicate", () => Source().AnyAsync(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.AllAsync <int>(null, s => true));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.AllAsync <int>(null, s => true, new CancellationToken()));
            await ArgumentNullTest("predicate", () => Source().AllAsync(null));
            await ArgumentNullTest("predicate", () => Source().AllAsync(null, new CancellationToken()));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.CountAsync <int>(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.CountAsync <int>(null, s => true));
            await ArgumentNullTest("predicate", () => Source().CountAsync(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.LongCountAsync <int>(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.LongCountAsync <int>(null, new CancellationToken()));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.LongCountAsync <int>(null, s => true));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.LongCountAsync <int>(null, s => true, new CancellationToken()));
            await ArgumentNullTest("predicate", () => Source().LongCountAsync(null));
            await ArgumentNullTest("predicate", () => Source().LongCountAsync(null, new CancellationToken()));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.MinAsync <int>(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.MinAsync <int>(null, new CancellationToken()));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.MinAsync <int, bool>(null, s => true));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.MinAsync <int, bool>(null, s => true, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source().MinAsync <int, bool>(null));
            await ArgumentNullTest("selector", () => Source().MinAsync <int, bool>(null, new CancellationToken()));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.MaxAsync <int>(null));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.MaxAsync <int>(null, new CancellationToken()));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.MaxAsync <int, bool>(null, s => true));
            await ArgumentNullTest("source", () => EntityFrameworkQueryableExtensions.MaxAsync <int, bool>(null, s => true, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source().MaxAsync <int, bool>(null));
            await ArgumentNullTest("selector", () => Source().MaxAsync <int, bool>(null, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <int>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <int?>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <long>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <long?>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <float>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <float?>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <double>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <double?>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <decimal>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <decimal?>)null).SumAsync());
            await ArgumentNullTest("source", () => ((IQueryable <int>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <int>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <int?>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <int?>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <long>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <long>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <long?>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <long?>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <float>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <float>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <float?>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <float?>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <double>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <double>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <double?>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <double?>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <decimal>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <decimal>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <decimal?>)null).SumAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <decimal?>)null).SumAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <int>().SumAsync((Expression <Func <int, int> >)null));
            await ArgumentNullTest("selector", () => Source <int?>().SumAsync((Expression <Func <int?, int> >)null));
            await ArgumentNullTest("selector", () => Source <long>().SumAsync((Expression <Func <long, int> >)null));
            await ArgumentNullTest("selector", () => Source <long?>().SumAsync((Expression <Func <long?, int> >)null));
            await ArgumentNullTest("selector", () => Source <float>().SumAsync((Expression <Func <float, int> >)null));
            await ArgumentNullTest("selector", () => Source <float?>().SumAsync((Expression <Func <float?, int> >)null));
            await ArgumentNullTest("selector", () => Source <double>().SumAsync((Expression <Func <double, int> >)null));
            await ArgumentNullTest("selector", () => Source <double?>().SumAsync((Expression <Func <double?, int> >)null));
            await ArgumentNullTest("selector", () => Source <decimal>().SumAsync((Expression <Func <decimal, int> >)null));
            await ArgumentNullTest("selector", () => Source <decimal?>().SumAsync((Expression <Func <decimal?, int> >)null));
            await ArgumentNullTest("source", () => ((IQueryable <int>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <int>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <int?>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <int?>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <long>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <long>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <long?>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <long?>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <float>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <float>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <float?>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <float?>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <double>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <double>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <double?>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <double?>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <decimal>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <decimal>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <decimal?>)null).AverageAsync());
            await ArgumentNullTest("source", () => ((IQueryable <decimal?>)null).AverageAsync(new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <int>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <int>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <int?>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <int?>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <long>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <long>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <long?>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <long?>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <float>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <float>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <float?>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <float?>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <double>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <double>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <double?>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <double?>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <decimal>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <decimal>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("source", () => ((IQueryable <decimal?>)null).AverageAsync(i => 0));
            await ArgumentNullTest("source", () => ((IQueryable <decimal?>)null).AverageAsync(i => 0, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <int>().AverageAsync((Expression <Func <int, int> >)null));
            await ArgumentNullTest("selector", () => Source <int>().AverageAsync((Expression <Func <int, int> >)null, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <int?>().AverageAsync((Expression <Func <int?, int> >)null));
            await ArgumentNullTest("selector", () => Source <int?>().AverageAsync((Expression <Func <int?, int> >)null, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <long>().AverageAsync((Expression <Func <long, int> >)null));
            await ArgumentNullTest("selector", () => Source <long>().AverageAsync((Expression <Func <long, int> >)null, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <long?>().AverageAsync((Expression <Func <long?, int> >)null));
            await ArgumentNullTest("selector", () => Source <long?>().AverageAsync((Expression <Func <long?, int> >)null, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <float>().AverageAsync((Expression <Func <float, int> >)null));
            await ArgumentNullTest("selector", () => Source <float>().AverageAsync((Expression <Func <float, int> >)null, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <float?>().AverageAsync((Expression <Func <float?, int> >)null));
            await ArgumentNullTest("selector", () => Source <float?>().AverageAsync((Expression <Func <float?, int> >)null, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <double>().AverageAsync((Expression <Func <double, int> >)null));
            await ArgumentNullTest("selector", () => Source <double>().AverageAsync((Expression <Func <double, int> >)null, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <double?>().AverageAsync((Expression <Func <double?, int> >)null));
            await ArgumentNullTest("selector", () => Source <double?>().AverageAsync((Expression <Func <double?, int> >)null, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <decimal>().AverageAsync((Expression <Func <decimal, int> >)null));
            await ArgumentNullTest("selector", () => Source <decimal>().AverageAsync((Expression <Func <decimal, int> >)null, new CancellationToken()));
            await ArgumentNullTest("selector", () => Source <decimal?>().AverageAsync((Expression <Func <decimal?, int> >)null));
            await ArgumentNullTest("selector", () => Source <decimal?>().AverageAsync((Expression <Func <decimal?, int> >)null, new CancellationToken()));

            // ReSharper restore AssignNullToNotNullAttribute
        }
Beispiel #23
0
#pragma warning restore CS8619 // Nullability of reference types in value doesn't match target type.

        /// <inheritdoc cref="EntityFrameworkQueryableExtensions.FirstOrDefaultAsync{TSource}(IQueryable{TSource}, Expression{Func{TSource, bool}}, CancellationToken)"/>
        public Task <TSource?> FirstOrDefaultAsync <TSource>(
            IQueryable <TSource> source,
            Expression <Func <TSource, bool> > predicate,
            CancellationToken token)
#pragma warning disable CS8619 // Nullability of reference types in value doesn't match target type.
        => EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(source, predicate, token);
 public Task <TSource> FirstOrDefaultAsync <TSource>(
     IQueryable <TSource> source,
     Expression <Func <TSource, bool> > predicate,
     CancellationToken cancellationToken = default) =>
 EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(source, predicate, cancellationToken);
Beispiel #25
0
 /// <inheritdoc cref="EntityFrameworkQueryableExtensions.FirstOrDefaultAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
 public static Task <TSource> FirstOrDefaultAsyncEF <TSource>(
     this IQueryable <TSource> source,
     CancellationToken cancellationToken = default)
 => EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(source, cancellationToken);
Beispiel #26
0
 /// <inheritdoc cref="EntityFrameworkQueryableExtensions.FirstOrDefaultAsync{TSource}(IQueryable{TSource}, CancellationToken)"/>
 public Task <TSource> FirstOrDefaultAsync <TSource>(
     IQueryable <TSource> source,
     CancellationToken token)
 => EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(source, token);
Beispiel #27
0
        ///// <summary>
        ///// Quitar el tracking.
        ///// </summary>
        ///// <typeparam name="T"></typeparam>
        ///// <param name="query"></param>
        ///// <returns></returns>
        //public static IQueryable<T> AsNoTracking<T>(this IQueryable<T> query) where T : class
        //{
        //    return EntityFrameworkQueryableExtensions.AsNoTracking(query);
        //}

        /// <summary>
        /// FirstOrDefault asíncrono.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <returns></returns>
        public static Task <T> FirstOrDefaultAsync <T>(this IQueryable <T> query) where T : class
        {
            return(EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query));
        }
 public Task <T> FirstOrDefaultAsync <T>(IQueryable <T> query, Expression <Func <T, bool> > predicate)
 {
     return(EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query, predicate));
 }
 public Task <T> FirstOrDefaultAsync <T>(IQueryable <T> query)
 {
     return(EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(query));
 }
Beispiel #30
0
 public async Task <Cover> GetByIdAsync(int coverId)
 {
     return(await EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(
                _brokerDbContext.Covers.Where(l => l.CoverId.Equals(coverId))));
 }