private static ExpressionStarter <T> HandleDate <T>(ExpressionStarter <T> predicate, object value, string domainName,
                                                            PropertyComparisonTypeEnum propertyComparison, ExpressionCombinationTypeEnum expressionCombination, Type type)
        {
            if (value == null)
            {
                return(predicate);
            }


            if (CheckIfDefaultValue(value, type))
            {
                return(predicate);
            }

            Expression <Func <T, bool> > condition = GetExpression <T>(propertyComparison, value, domainName);


            switch (expressionCombination)
            {
            case ExpressionCombinationTypeEnum.And:
                predicate.And(condition);
                break;

            case ExpressionCombinationTypeEnum.Or:
                predicate.Or(condition);
                break;

            default:
                predicate.And(condition);
                break;
            }

            return(predicate);
        }
示例#2
0
        public IEnumerable <User> GetBy(UserFilterModel filterModel)
        {
            if (filterModel == null)
            {
                throw new ArgumentNullException(nameof(filterModel));
            }

            ExpressionStarter <JToken> filterBuilder = PredicateBuilder.New <JToken>();

            if (!string.IsNullOrEmpty(filterModel.Id))
            {
                filterBuilder.And(x => x["Id"].ToString() == filterModel.Id);
            }

            if (!string.IsNullOrEmpty(filterModel.Email))
            {
                filterBuilder.And(x => x["Email"].ToString() == filterModel.Email);
            }

            if (filterModel.ToDate.HasValue)
            {
                filterBuilder.And(x => x["Birthday"].Value <DateTime>() <= filterModel.ToDate.Value);
            }

            IEnumerable <User> dataEntities = _dataContext.Items.Value
                                              .Where(filterBuilder)
                                              .Select(x => x.ToObject <User>());

            return(dataEntities ?? Enumerable.Empty <User>());
        }
示例#3
0
        public static Func <Transaction, bool> CreateTransactionFilter(string currencyCode, DateTime?dateFrom,
                                                                       DateTime?dateTo, string status)
        {
            ExpressionStarter <Transaction> predicate = PredicateBuilder.New <Transaction>(true);

            if (!string.IsNullOrEmpty(currencyCode))
            {
                predicate = predicate.And(c => c.CurrencyCode == currencyCode);
            }

            if (dateFrom != null)
            {
                predicate = predicate.And(c => c.TransactionDate.CompareTo(dateFrom.Value) >= 0);
            }

            if (dateTo != null)
            {
                predicate = predicate.And(c => c.TransactionDate.CompareTo(dateTo.Value) <= 0);
            }

            if (!string.IsNullOrEmpty(status) && Enum.IsDefined(typeof(TransactionStatusEnum), status))
            {
                predicate = predicate.And(c =>
                                          c.TransactionStatus == (TransactionStatusEnum)Enum.Parse(typeof(TransactionStatus), status));
            }

            return(predicate.Compile());
        }
示例#4
0
        private static ExpressionStarter <IResourceIndexed> CollectionNotEqualToPredicate(Search <IResourceIndexed> Search, ExpressionStarter <IResourceIndexed> NewPredicate, SearchParameterNumber SearchTypeNumber, SearchParameterNumberValue SearchValue)
        {
            var NotEqualToExpression         = Search.NumberCollectionAllNotEqualTo(SearchTypeNumber.Id, Common.Tools.DecimalSupport.CalculateLowNumber(SearchValue.Value, SearchValue.Scale), SearchValue.Value, Common.Tools.DecimalSupport.CalculateHighNumber(SearchValue.Value, SearchValue.Scale));
            var CollectionNotNull_Expression = Search.SearchParameterIdIsNotNull <Index.IQuantityIndex>(SearchTypeNumber.Id);

            ExpressionStarter <IResourceIndexed> NewAndPredicate = LinqKit.PredicateBuilder.New <IResourceIndexed>();

            NewAndPredicate = NewAndPredicate.And(NotEqualToExpression);
            NewAndPredicate = NewAndPredicate.And(CollectionNotNull_Expression);

            NewPredicate = NewPredicate.Or(NewAndPredicate);

            return(NewPredicate);
        }
        public Expression <Func <Chat, bool> > GetChatExpression(SearchChatVm templateChat)
        {
            ExpressionStarter <Chat> chatCondition = PredicateBuilder.New <Chat>();

            if (!string.IsNullOrWhiteSpace(templateChat.Name))
            {
                chatCondition = chatCondition.And(chat => chat.Name.ToLower() == templateChat.Name.ToLower());
            }
            if (templateChat.Tag != null)
            {
                chatCondition = chatCondition.And(chat => chat.Tag == templateChat.Tag);
            }
            return((Expression <Func <Chat, bool> >)chatCondition.Expand());
        }
示例#6
0
        private static ExpressionStarter <ResCurrentType> CollectionNotEqualToPredicate(ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterNumber SearchTypeNumber, SearchParameterNumberValue SearchValue)
        {
            var NotEqualToExpression         = Search.NumberCollectionAllNotEqualTo(SearchTypeNumber.Id, Common.Tools.DecimalSupport.CalculateLowNumber(SearchValue.Value, SearchValue.Scale), SearchValue.Value, Common.Tools.DecimalSupport.CalculateHighNumber(SearchValue.Value, SearchValue.Scale));
            var CollectionNotNull_Expression = Search.SearchParameterIdIsNotNull <ResIndexQuantityType>(SearchTypeNumber.Id);

            ExpressionStarter <ResCurrentType> NewAndPredicate = LinqKit.PredicateBuilder.New <ResCurrentType>();

            NewAndPredicate = NewAndPredicate.And(NotEqualToExpression);
            NewAndPredicate = NewAndPredicate.And(CollectionNotNull_Expression);

            NewPredicate = NewPredicate.Or(NewAndPredicate);

            return(NewPredicate);
        }
示例#7
0
 private static void GetByDate(this ExpressionStarter <FileStorage> predicate, DateTime?startDate, DateTime?endDate)
 {
     if (startDate.HasValue && endDate.HasValue)
     {
         predicate.And(x => startDate <= x.CreateDate && x.CreateDate <= endDate);
     }
     else if (startDate.HasValue && !endDate.HasValue)
     {
         predicate.And(x => startDate <= x.CreateDate);
     }
     else if (!startDate.HasValue && endDate.HasValue)
     {
         predicate.And(x => x.CreateDate <= endDate);
     }
 }
        public async Task <bool> ExecuteQueryAsync(Queries.LocationWithNameDoesNotExist query,
                                                   CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(query?.Name) ||
                string.IsNullOrWhiteSpace(this.currentUserProvider?.User?.Name))
            {
                return(false);
            }

            using (ApplicationContext context = this.databaseContextProvider.CreateContext())
            {
                ExpressionStarter <Location> predicate = PredicateBuilder.New <Location>(entity =>
                                                                                         entity.Owner.Equals(this.currentUserProvider.User.Name.ToSha256(),
                                                                                                             StringComparison.InvariantCultureIgnoreCase) &&
                                                                                         entity.Name.Equals(query.Name, StringComparison.InvariantCultureIgnoreCase));

                if (!string.IsNullOrWhiteSpace(query.ExceptId))
                {
                    predicate = predicate.And(entity =>
                                              !entity.Id.Equals(query.ExceptId, StringComparison.InvariantCultureIgnoreCase));
                }

                return(!await context.Locations.AnyAsync(predicate, cancellationToken).ConfigureAwait(false));
            }
        }
        public Task <IEnumerable <PublishedProviderResult> > GetPublishedProviderResultsForSpecificationAndStatus(string specificationId, UpdatePublishedAllocationLineResultStatusModel filterCriteria)
        {
            IQueryable <PublishedProviderResult> results = _cosmosRepository.Query <PublishedProviderResult>(enableCrossPartitionQuery: true).Where(m => m.SpecificationId == specificationId && m.FundingStreamResult.AllocationLineResult.Current.Status == filterCriteria.Status);

            ExpressionStarter <PublishedProviderResult> providerPredicate = PredicateBuilder.New <PublishedProviderResult>(false);

            foreach (UpdatePublishedAllocationLineResultStatusProviderModel provider in filterCriteria.Providers)
            {
                string providerId = provider.ProviderId;
                providerPredicate = providerPredicate.Or(p => p.ProviderId == providerId);

                ExpressionStarter <PublishedProviderResult> allocationLinePredicate = PredicateBuilder.New <PublishedProviderResult>(false);
                foreach (string allocationLineId in provider.AllocationLineIds)
                {
                    string temp = allocationLineId;
                    allocationLinePredicate = allocationLinePredicate.Or(a => a.FundingStreamResult.AllocationLineResult.AllocationLine.Id == temp);
                }

                providerPredicate = providerPredicate.And(allocationLinePredicate);
            }

            results = results.AsExpandable().Where(providerPredicate);
            List <PublishedProviderResult> result = new List <PublishedProviderResult>(results);

            return(Task.FromResult(result.AsEnumerable()));
        }
示例#10
0
 private static void GetBySearchString(this ExpressionStarter <FileStorage> predicate, string searchString)
 {
     if (!String.IsNullOrEmpty(searchString))
     {
         predicate.And(x => x.Name.ToLower().Contains(searchString.ToLower()));
     }
 }
示例#11
0
 private static void GetByUserGroups(this ExpressionStarter <FileStorage> predicate, IEnumerable <int> userGroupIds)
 {
     if (userGroupIds.Count() > 0)
     {
         predicate.And(x => x.OwnerId.HasValue && x.Owner.UserInGroups.Any(y => userGroupIds.Contains(y.GroupId)) ||
                       x.Permissions.Any(y => !y.EndDate.HasValue && y.Recipient.UserInGroups.Any(z => userGroupIds.Contains(z.GroupId))));
     }
 }
示例#12
0
 protected void PredicateAnd(Expression <Func <TEntity, bool> > expression)
 {
     if (expression != null)
     {
         hasPredicate = true;
         predicate    = predicate.And(expression);
     }
 }
示例#13
0
 private static void GetByDepartments(this ExpressionStarter <FileStorage> predicate, IEnumerable <int> departmentIds)
 {
     if (departmentIds.Count() > 0)
     {
         predicate.And(x => x.ClientId.HasValue && x.Client.Departments.Any(y => departmentIds.Contains(y.Id)) ||
                       x.OwnerId.HasValue && x.Owner.DepartmentId.HasValue && departmentIds.Contains(x.Owner.DepartmentId.Value) ||
                       x.Permissions.Any(y => !y.EndDate.HasValue && y.Recipient.DepartmentId.HasValue && departmentIds.Contains(y.Recipient.DepartmentId.Value)));
     }
 }
示例#14
0
        public static Expression <Func <T, bool> > AndIf <T>(this ExpressionStarter <T> expression, Expression <Func <T, bool> > expr2)
        {
            if (expr2 != null)
            {
                return(expression.And(expr2));
            }

            return(expression);
        }
        public static ExpressionStarter <ToDoEntity> CreateSearchPredicate(SearchRequestDto request)
        {
            ExpressionStarter <ToDoEntity> predicate = PredicateBuilder.New <ToDoEntity>(true);

            if (request.TableId != null)
            {
                predicate.And(x => x.TableId == request.TableId);
            }

            return(predicate);
        }
        private async Task <ExpressionStarter <ReportInstance> > AssertFilterOnStage(string qualifiedName, ExpressionStarter <ReportInstance> predicate)
        {
            var compareDate = await PrepareComparisonForFeedbackReportDateAsync();

            switch (qualifiedName)
            {
            case "Confirm Report Data":
                predicate = predicate.And(ri => ri.Activities.Any(a => a.QualifiedName == qualifiedName && a.Current == true && a.CurrentStatus.Description != "DELETED") && ri.Tasks.Any(t => t.TaskStatusId != Core.Aggregates.ReportInstanceAggregate.TaskStatus.Cancelled.Id && t.TaskStatusId != Core.Aggregates.ReportInstanceAggregate.TaskStatus.Completed.Id));
                break;

            case "Set MedDRA and Causality":
                predicate = predicate.And(ri => ri.Activities.Any(a => a.QualifiedName == qualifiedName && a.Current == false && a.CurrentStatus.Description == "CAUSALITYCONFIRMED" && a.LastUpdated >= compareDate));
                break;

            case "Extract E2B":
                predicate = predicate.And(ri => ri.Activities.Any(a => a.QualifiedName == qualifiedName && a.Current == true && a.CurrentStatus.Description == "E2BSUBMITTED" && a.LastUpdated >= compareDate));
                break;
            }

            return(predicate);
        }
示例#17
0
        public Expression <Func <User, bool> > GetUserExpression(SearchUserVm templateUser)
        {
            ExpressionStarter <User> userCondition = PredicateBuilder.New <User>();

            if (!string.IsNullOrWhiteSpace(templateUser.NameFirst))
            {
                userCondition = userCondition.And(user => user.NameFirst.ToLower() == templateUser.NameFirst.ToLower());
            }
            if (!string.IsNullOrWhiteSpace(templateUser.NameSecond))
            {
                userCondition = userCondition.And(user => user.NameSecond.ToLower() == templateUser.NameSecond.ToLower());
            }
            if (!string.IsNullOrWhiteSpace(templateUser.City))
            {
                userCondition = userCondition.And(user => user.City.ToLower() == templateUser.City.ToLower());
            }
            if (!string.IsNullOrWhiteSpace(templateUser.Country))
            {
                userCondition = userCondition.And(user => user.Country.ToLower() == templateUser.Country.ToLower());
            }
            if (templateUser.Birthday != null)
            {
                userCondition = userCondition.And(user => user.Birthday == templateUser.Birthday);
            }
            if (templateUser.Tag != null)
            {
                userCondition = userCondition.And(user => user.Tag == templateUser.Tag);
            }
            return((Expression <Func <User, bool> >)userCondition.Expand());
        }
示例#18
0
        public async Task <ServiceResponse <List <Movie> > > Get(MovieFilter model)
        {
            ExpressionStarter <Movie> expression = PredicateBuilder.New <Movie>(true);

            if (model.Actors?.Count() > 0)
            {
                expression = expression.And(prop => prop.Actors.Any(a => model.Actors.Contains(a.ActorId)));
            }
            if (model.Genres?.Count() > 0)
            {
                expression = expression.And(prop => prop.Genres.Any(a => model.Genres.Contains(a.GenreId)));
            }
            if (model.PriceRange != null && !model.PriceRange.Equals(""))
            {
                expression = expression.And(prop => prop.Price >= model.PriceMin && prop.Price <= model.PriceMax);
            }

            var responseD = _movieRepo.Pagining(expression, ((model.PageNumber - 1) * model.PageSize), model.PageSize, model.OrderColumn, (OrderDirection)model.OrderBy, true);
            var response  = await responseD.ToListAsync();

            return(new ServiceResponse <List <Movie> >(response, true));
        }
示例#19
0
        public async Task <ServiceResponse <List <Genre> > > Get(GenreFilter model)
        {
            ExpressionStarter <Genre> expression = PredicateBuilder.New <Genre>(true);

            if (model.Name.Length > 0)
            {
                expression = expression.And(prop => model.Name.Contains(prop.Name));
            }
            var responseD = _genreRepo.Pagining(expression, ((model.PageNumber - 1) * model.PageSize), model.PageSize, model.OrderColumn, (OrderDirection)model.OrderBy, true);
            var response  = await responseD.ToListAsync();

            return(new ServiceResponse <List <Genre> >(response, true));
        }
        private async Task <ExpressionStarter <ReportInstance> > AssertFacilityPermissions(ExpressionStarter <ReportInstance> predicate)
        {
            var userName     = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var userFromRepo = await _userRepository.GetAsync(u => u.UserName == userName, new string[] { "Facilities.Facility" });

            if (userFromRepo == null)
            {
                throw new KeyNotFoundException("Unable to locate user");
            }
            var validfacilities = userFromRepo.Facilities.Select(uf => uf.Facility.FacilityCode).ToArray();

            predicate = predicate.And(ri => validfacilities.Contains(ri.FacilityIdentifier));
            return(predicate);
        }
        private static void PredicateBuilderForCrud(ref ExpressionStarter <RoleEntityClaim> predicate, Crud crud)
        {
            switch (crud)
            {
            case Crud.Create:
                predicate = predicate.And(p => p.CanCreate);
                break;

            case Crud.Update:
                predicate = predicate.And(p => p.CanUpdate);
                break;

            case Crud.Delete:
                predicate = predicate.And(p => p.CanDelete);
                break;

            case Crud.Select:
                predicate = predicate.And(p => p.CanSelect);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(crud), crud, null);
            }
        }
示例#22
0
        public static ExpressionStarter <T> PredicateByOperationType <T>(this ExpressionStarter <T> predicate,
                                                                         BitwiseOperation operation,
                                                                         Expression <Func <T, bool> > expr)
        {
            switch (operation)
            {
            case BitwiseOperation.And:
                predicate = predicate.And(expr);
                break;

            case BitwiseOperation.Or:
                predicate = predicate.Or(expr);
                break;
            }

            return(predicate);
        }
示例#23
0
        private List <Quote> GetMatchingQuotes(CreateReportViewModel model)
        {
            List <int> selectedLocations     = model.Locations.Where(checkbox => checkbox.IsChecked).Select(checkbox => checkbox.Item.Id).ToList();
            double     maxDiscountPercentage = model.MaxDiscountPercentage ?? double.MaxValue;
            double     minDiscountPercentage = model.MinDiscountPercentage ?? double.MinValue;
            double     maxDiscountDollars    = model.MaxDiscountDollars ?? double.MaxValue;
            double     minDiscountDollars    = model.MinDiscountDollars ?? double.MinValue;
            string     city    = model.City ?? string.Empty;
            string     address = model.Address ?? string.Empty;

            model.StartDate = model.StartDate ?? DateTime.MinValue;
            model.EndDate   = model.EndDate ?? DateTime.MaxValue;

            address = address.ToLower(); /* seems EF does something odd when we next this ToLower()
                                          * call below (empty string never matches anything when it should match all) */

            ExpressionStarter <Quote> isMostlyMatched = PredicateBuilder.New <Quote>(q =>
                                                                                     (q.Customer.AddressLine1 + q.Customer.AddressLine2).ToLower().Contains(address) &&
                                                                                     selectedLocations.Contains(q.Location.Id) &&
                                                                                     model.StartDate <= q.DateCreated && q.DateCreated <= model.EndDate &&
                                                                                     minDiscountPercentage <= q.DiscountPercentage && q.DiscountPercentage <= maxDiscountPercentage &&
                                                                                     minDiscountDollars <= q.EligibleCost && q.EligibleCost <= maxDiscountDollars &&
                                                                                     q.Customer.City.Contains(city));

            // These ones only work with exact equality
            ExpressionStarter <Quote> matchesZip, matchesState, matchesNumberInHousehold;

            matchesZip = matchesNumberInHousehold = matchesState = PredicateBuilder.New <Quote>(true);
            if (model.ZipCode != null)
            {
                matchesZip.DefaultExpression = q => q.Customer.ZipCode == model.ZipCode;
            }
            if (model.State != null)
            {
                matchesState.DefaultExpression = q => q.Customer.State == model.State;
            }
            if (model.NumberInHousehold != null)
            {
                matchesNumberInHousehold.DefaultExpression = q => q.CurrentNumberInHousehold == model.NumberInHousehold;
            }

            return(IncludeAllNavigationProperties(db.Quotes)
                   .AsExpandable()
                   .Where(isMostlyMatched.And(matchesZip.And(matchesState).And(matchesNumberInHousehold))).ToList());
        }
示例#24
0
 public async Task <GetBaseLedgerPostingsResponse> GetBaseLedgerPostingsAsync(GetBaseLedgerPostingsRequest request)
 {
     return(await Task.Run(() =>
     {
         GetBaseLedgerPostingsResponse _response = new GetBaseLedgerPostingsResponse();
         using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities())
         {
             ExpressionStarter <LedgerPosting> _predicateLedgerPosting = PredicateBuilder.New <LedgerPosting>(true);
             if (request.Id.HasValue)
             {
                 _predicateLedgerPosting = _predicateLedgerPosting.And(p => p.Id == request.Id);
             }
             List <LedgerPosting> _ledgerPostings = _dbContext.LedgerPostings.AsExpandable().Where(_predicateLedgerPosting).ToList();
             if (_ledgerPostings.Any())
             {
                 _response.BaseObjects = _ledgerPostings.ToBaseLedgerPostings();
             }
         }
         return _response;
     }));
 }
示例#25
0
 public async Task <GetBaseSuffixPrifixesResponse> GetBaseSuffixPrifixesAsync(GetBaseSuffixPrifixesRequest request)
 {
     return(await Task.Run(() =>
     {
         GetBaseSuffixPrifixesResponse _response = new GetBaseSuffixPrifixesResponse();
         using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities())
         {
             ExpressionStarter <SuffixPrefix> _predicateSuffixPrifix = PredicateBuilder.New <SuffixPrefix>(true);
             if (request.Id.HasValue)
             {
                 _predicateSuffixPrifix = _predicateSuffixPrifix.And(p => p.Id == request.Id);
             }
             List <SuffixPrefix> _SuffixPrifixes = _dbContext.SuffixPrefixes.AsExpandable().Where(_predicateSuffixPrifix).ToList();
             if (_SuffixPrifixes.Any())
             {
                 _response.BaseObjects = _SuffixPrifixes.ToBaseSuffixPrifix();
             }
         }
         return _response;
     }));
 }
示例#26
0
 public async Task <GetBaseFieldsResponse> GetBaseFieldsAsync(GetBaseFieldsRequest request)
 {
     return(await Task.Run(() =>
     {
         GetBaseFieldsResponse _response = new GetBaseFieldsResponse();
         using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities())
         {
             ExpressionStarter <Field> _predicateField = PredicateBuilder.New <Field>(true);
             if (request.Id.HasValue)
             {
                 _predicateField = _predicateField.And(p => p.Id == request.Id);
             }
             List <Field> _Fields = _dbContext.Fields.AsExpandable().Where(_predicateField).ToList();
             if (_Fields.Any())
             {
                 _response.BaseObjects = _Fields.ToBaseField();
             }
         }
         return _response;
     }));
 }
 public async Task <GetBaseBudgetDetailsResponse> GetBaseBudgetDetailsAsync(GetBaseBudgetDetailsRequest request)
 {
     return(await Task.Run(() =>
     {
         GetBaseBudgetDetailsResponse _response = new GetBaseBudgetDetailsResponse();
         using (AsyncAutomateAccountingEntities _dbContext = new AsyncAutomateAccountingEntities())
         {
             ExpressionStarter <BudgetDetail> _predicateBudgetDetail = PredicateBuilder.New <BudgetDetail>(true);
             if (request.Id.HasValue)
             {
                 _predicateBudgetDetail = _predicateBudgetDetail.And(p => p.Id == request.Id);
             }
             List <BudgetDetail> _BudgetDetails = _dbContext.BudgetDetails.AsExpandable().Where(_predicateBudgetDetail).ToList();
             if (_BudgetDetails.Any())
             {
                 _response.BaseObjects = _BudgetDetails.ToBaseBudgetDetail();
             }
         }
         return _response;
     }));
 }
示例#28
0
        public async Task <List <ExpressionStarter <ResourceStore> > > ChainEntry(AppDbContext AppDbContext, Common.Enums.ResourceType ParentResourceTypeContext, IList <ISearchQueryBase> SearchQueryList)
        {
            var Result = new List <ExpressionStarter <ResourceStore> >();
            IEnumerable <ISearchQueryBase> ChainedSearchQueryList = SearchQueryList.Where(x => x.ChainedSearchParameter is object);
            IQueryable <ResourceStore>     ResourceStoreQuery     = AppDbContext.Set <ResourceStore>();

            foreach (ISearchQueryBase ChainSearchQuery in ChainedSearchQueryList)
            {
                if (ChainSearchQuery.ChainedSearchParameter is null)
                {
                    throw new NullReferenceException(nameof(ChainSearchQuery.ChainedSearchParameter));
                }

                ExpressionStarter <IndexReference> ExpressionStarterIndexReference = PredicateBuilder.New <IndexReference>(false);
                ExpressionStarterIndexReference = await ChainRecursion2(AppDbContext, ExpressionStarterIndexReference, ChainSearchQuery);

                ExpressionStarter <ResourceStore> ExpressionStarterResourceStore = PredicateBuilder.New <ResourceStore>(false);
                ExpressionStarterResourceStore = ExpressionStarterResourceStore.And(r => r.ReferenceIndexList.Any(ExpressionStarterIndexReference));
                Result.Add(ExpressionStarterResourceStore);
            }
            return(Result);
        }
示例#29
0
        /// <summary>
        /// combine linqkit predicate
        /// </summary>
        /// <returns></returns>
        public ExpressionStarter <T> GetPredicate()
        {
            ExpressionStarter <T> linqkitFilter = PredicateBuilder.New <T>(true);


            _filters.Get()?
            .ToList()
            .ForEach(x =>
            {
                switch (x.Key)
                {
                case AppendPredicateWith.And:
                    linqkitFilter = linqkitFilter.And(x.Value);
                    break;

                case AppendPredicateWith.Or:
                    linqkitFilter = linqkitFilter.Or(x.Value);
                    break;
                }
            });

            return(linqkitFilter);
        }
        protected async Task <TEntity> GetById(string id, DbContext context, ExpressionStarter <TEntity> predicate)
        {
            var idRaw = GetIdRaw(id);

            var getByIdSpec = new GetByIdSpecification <TEntity, TKey>((TKey)idRaw);

            predicate.And(getByIdSpec.IsSatisfiedBy());

            var query = context.Set <TEntity>().AsQueryable();

            if (_parameters.IncludeProperties != null)
            {
                foreach (var property in _parameters.IncludeProperties)
                {
                    query = query.Include(property);
                }
            }


            var entity = await query.AsExpandable().FirstOrDefaultAsync(predicate);

            return(entity);
        }