/// <summary>Finds all the entities that match the expression.</summary> /// <param name="expression">The search-specification.</param> /// <param name="sortRules">The specification of the sort rules that must be applied. Use <see langword="null"/> to ignore the ordering.</param> /// <param name="maximumResults">The maximum number of results that must be retrieved. Use '-1' to retrieve all results.</param> /// <param name="includePaths">The dot-separated lists of related objects to return in the query results.</param> /// <param name="dataSourceInfo">The parameter is not used.</param> /// <returns>The items that match the expression.</returns> protected override IEnumerable <TEntity> FindAllCore(Func <TEntity, bool> expression, SortSpecifications <TEntity> sortRules, int maximumResults, string[] includePaths, DataSourceInfo dataSourceInfo) { MemoryStore <TEntity> memoryStore = this.SelectMemoryStore(dataSourceInfo); try { this.temporaryStorageLock.EnterReadLock(); memoryStore.EnterReadLock(); IEnumerable <TEntity> results = this.ConcatStorage(dataSourceInfo); results = results.Where(item => expression(item)).OrderBy(sortRules); if (maximumResults == -1) { return(results.ToList()); } else { return(results.Take(maximumResults).ToList()); } } finally { memoryStore.ExitReadLock(); this.temporaryStorageLock.ExitReadLock(); } }
/// <summary>Sorts the sequence according to the sort specifications.</summary> /// <typeparam name="T">The type of object that must be sorted.</typeparam> /// <param name="source">The sequence that must be sorted.</param> /// <param name="sortSpecifications">The specifications for the sorting.</param> /// <returns>The sorted sequence.</returns> public static IEnumerable <T> OrderBy <T>(this IEnumerable <T> source, SortSpecifications <T> sortSpecifications) { Guard.ArgumentIsNotNull(source, nameof(source), "The IEnumerable instance is mandatory."); if (sortSpecifications == null) { return(source); } else { return(sortSpecifications.Sort(source)); } }
/// <summary>Finds the first entity that matches the expression or returns the default value if there were no matches.</summary> /// <param name="expression">The search-specification.</param> /// <param name="sortRules">The specification of the sort rules that must be applied. Use <see langword="null"/> to ignore the ordering.</param> /// <param name="includePaths">The dot-separated lists of related objects to return in the query results.</param> /// <param name="dataSourceInfo">The parameter is not used.</param> /// <param name="defaultValue">The value that must be returned if there were no matches.</param> /// <returns>The first result or the default value.</returns> protected override TEntity FindFirstCore(Func <TEntity, bool> expression, SortSpecifications <TEntity> sortRules, string[] includePaths, DataSourceInfo dataSourceInfo, TEntity defaultValue) { MemoryStore <TEntity> memoryStore = this.SelectMemoryStore(dataSourceInfo); try { this.temporaryStorageLock.EnterReadLock(); memoryStore.EnterReadLock(); return(this.ConcatStorage(dataSourceInfo).OrderBy(sortRules).FirstOrDefault(expression, defaultValue)); } finally { memoryStore.ExitReadLock(); if (this.temporaryStorageLock.IsReadLockHeld) { this.temporaryStorageLock.ExitReadLock(); } } }
/// <summary>Since retrieval of the entity is handled by the parent entity's repository, this method throws a /// <see cref="NotSupportedException"/>.</summary> /// <param name="expression">The parameter is not used.</param> /// <param name="sortRules">The specification of the sort rules that must be applied. Use <see langword="null"/> to ignore the ordering.</param> /// <param name="includePaths">The dot-separated lists of related objects to return in the query results.</param> /// <param name="dataSourceInfo">Information about the data source that may not have been set at an earlier stage.</param> /// <param name="defaultValue">The parameter is not used.</param> /// <returns>Not applicable.</returns> /// <exception cref="NotSupportedException">Always, since this operation is not supported by this type of repository.</exception> protected override TEntity FindFirstCore(Func <TEntity, bool> expression, SortSpecifications <TEntity> sortRules, string[] includePaths, DataSourceInfo dataSourceInfo, TEntity defaultValue) { throw new NotSupportedException("This repository cannot be used to retrieve entities."); }
/// <summary>Since retrieval of these entities is handled by the parent entity's repository, this method throws a /// <see cref="NotSupportedException"/>.</summary> /// <param name="expression">The parameter is not used.</param> /// <param name="sortRules">The specification of the sort rules that must be applied. Use <see langword="null"/> to ignore the ordering.</param> /// <param name="maximumResults">The maximum number of results that must be retrieved. Use '-1' to retrieve all results.</param> /// <param name="includePaths">The dot-separated lists of related objects to return in the query results.</param> /// <param name="dataSourceInfo">Information about the data source that may not have been set at an earlier stage.</param> /// <returns>Not applicable.</returns> /// <exception cref="NotSupportedException">Always, since this operation is not supported by this type of repository.</exception> protected override IEnumerable <TEntity> FindAllCore(Func <TEntity, bool> expression, SortSpecifications <TEntity> sortRules, int maximumResults, string[] includePaths, DataSourceInfo dataSourceInfo) { throw new NotSupportedException("This repository cannot be used to retrieve entities."); }