public virtual PageCollection <TModel> Page <TModel>(PageQueryParameter <TEntity> parameter) where TModel : PropertyOwnerModel <TPropertyValueEntity> { var repository = _repositoryProviderProvider.Provide <IEntityQueryRepository>().Provide(); var context = CreatePageQueryContext(parameter); var entities = repository.Page(context); var models = Mapper.Map <List <TModel> >(entities.List); var valueRepository = _repositoryProviderProvider.Provide <IPropertyValueQueryRepository>().Provide(); var valueContext = new GroupPropertyValueContext <TPropertyValueEntity> { ContextProvider = _contextProvider, Keys = entities.List.Select(s => s.Id).ToList(), PropertyValueKeyProvider = _propertyValueKeyProviderSelector.Select(), UserId = UserContext.Current.UserId }; var values = valueRepository.Grouping(valueContext); models.ForEach(model => { var vs = values.FirstOrDefault(x => x.Key == model.Id); if (vs == null) { return; } model.Properties = vs?.ToList(); }); return(new PageCollection <TModel> { PageSize = entities.PageSize, Count = entities.Count, List = models, Page = entities.Page }); }
public IEnumerable <IGrouping <Guid, TPropertyValue> > Grouping <TPropertyValue>(GroupPropertyValueContext <TPropertyValue> context) where TPropertyValue : PropertyValueEntity { using (var db = context.ContextProvider.Provide()) { var values = db.Set <TPropertyValue>() .Where(s => s.UserId == context.UserId) .Where(context.CreatePredicate()) .ToList(); return(values.GroupBy(context.GroupKey().Compile())); } }