/// <summary> /// Filters the specified collection. /// </summary> /// <param name="collection"> /// The collection. /// </param> /// <returns> /// A filtered collection. /// </returns> public IQueryable <TEntity> Filter(IQueryable <TEntity> collection) { if (_baseFilter == null) { return(collection.Where(_predicate.Expand())); } return(_baseFilter.Filter(collection).Where(_predicate.Expand())); }
public IEnumerable <IEntity> Filter(IEnumerable <IEntity> entities, DynamicValueContext context) { IEntity[] allEntities = entities.ToArray(); IEntity[] first = m_firstFilter.Filter(allEntities, context).ToArray(); for (int i = 0; i < first.Length; i++) { yield return(first[i]); } foreach (IEntity item in m_secondFilter.Filter(allEntities, context)) { if (!first.Contains(item)) { yield return(item); } } }
public override bool GetValue(DynamicValueContext context, out int value) { DynamicValueFightContext dynamicValueFightContext = context as DynamicValueFightContext; if (dynamicValueFightContext != null) { IEnumerable <IEntityWithBoardPresence> entities = dynamicValueFightContext.fightStatus.EnumerateEntities <IEntityWithBoardPresence>(); int num = 0; foreach (IEntity item in m_entity.Filter(entities, context)) { num += item.GetCarac(m_carac); } value = num; return(true); } value = 0; return(false); }
public async Task <IList <TEntity> > Search(SearchBase <TEntity> searchCriteria, IEnumerable <string> includes = null) { try { using (var context = new EntityContext()) { IQueryable <TEntity> query = GetDBSet(context); query = SetIncludes(includes, query); query = _entityFilter.Filter(query, searchCriteria); return(await query.ToListAsync <TEntity>()); } } catch (Exception ex) { //TODO return(null); } }
public IList <TEntity> List(IEntityFilter <TEntity> filter = null, IEntitySorter <TEntity> sorter = null, int?page = null, int?pageSize = null, IEntityLoader <TEntity> loader = null) { if ((page.HasValue || pageSize.HasValue) && sorter == null) { throw new ArgumentException("You have to define a sorting order if you specify a page or pageSize! (IEntitySorter was null)"); } if (page.HasValue && !pageSize.HasValue) { throw new ArgumentException("You have to define a pageSize if you specify a page!"); } var entities = Entities; if (filter != null) { entities = filter.Filter(entities); } if (sorter != null) { entities = sorter.Sort(entities); } if (page != null) { entities = entities.Skip(pageSize.Value * page.Value); } if (pageSize != null) { entities = entities.Take(pageSize.Value); } entities = entities.InterceptWith(new QueryableEntitiesVisitor()); if (loader != null) { return(loader.Load(entities)); } return(entities.ToList()); }
public IEnumerable <IEntity> Filter(IEnumerable <IEntity> entities, DynamicValueContext context) { List <IEntity> entityList = ListPool <IEntity> .Get(); List <IEntity> filtered = ListPool <IEntity> .Get(); entityList.AddRange(entities); filtered.AddRange(m_filter.Filter(entityList, context)); int coordCount = entityList.Count; int filteredCount = filtered.Count; int num2; for (int i = 0; i < coordCount; i = num2) { IEntity entity = entityList[i]; int num = 0; while (true) { if (num < filteredCount) { if (entity == filtered[num]) { break; } num++; continue; } yield return(entity); break; } num2 = i + 1; } ListPool <IEntity> .Release(entityList); ListPool <IEntity> .Release(filtered); }