/// <summary> /// Convert the received value into an <see cref="IActionResult"/>. /// <para> /// Catches <see cref="ValidationException"/> and converts it to /// an appropriate <see cref="IActionResult"/>. /// </para> /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="mapping"> /// The function to convert the value into an <see cref="IActionResult"/>. /// </param> /// <returns>An instance of <see cref="IProviderObservable{IActionResult}"/>.</returns> public static IProviderObservable <IActionResult> ToActionResult <TSource>( this IProviderObservable <TSource> observable, Func <TSource, IActionResult> mapping) => observable.Map(mapping) .Catch((ValidationException exception) => { var actionResult = exception.Error == null ? ToStatusResult(exception) : ToObjectResult(exception); return(Observable.Single(actionResult, observable.ServiceProvider)); });
/// <summary> /// Emits the first element of a sequence, or a default /// value if the sequence contains no elements. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <returns>An instance of <see cref="IProviderObservable{TSource}"/>.</returns> public static IProviderObservable <TSource> FirstOrDefault <TSource>( this IProviderObservable <IQueryable <TSource> > observable) => observable.Map(s => s.FirstOrDefault());
/// <summary> /// Emits the first element of a sequence that satisfies a /// specified condition or a default value if no such element is found. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="predicate">A function to test each element for a condition.</param> /// <returns>An instance of <see cref="IProviderObservable{TSource}"/>.</returns> public static IProviderObservable <TSource> FirstOrDefault <TSource>( this IProviderObservable <IQueryable <TSource> > observable, Expression <Func <TSource, bool> > predicate) => observable.Map(s => s.FirstOrDefault(predicate));
/// <summary> /// Specifies additional related data to be further included based on a /// related type that was just included. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <typeparam name="TPreviousProperty">The type of the previous property.</typeparam> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="navigationPropertyPath"> /// A lambda expression representing the navigation property to be /// included (<c>t => t.Property1</c>). /// </param> /// <returns>An instance of <see cref="IProviderObservable{TSource}"/>.</returns> public static IProviderObservable <IIncludableQueryable <TSource, TProperty> > ThenInclude <TSource, TPreviousProperty, TProperty>( this IProviderObservable <IIncludableQueryable <TSource, TPreviousProperty> > observable, Expression <Func <TPreviousProperty, TProperty> > navigationPropertyPath) where TSource : class => observable.Map(s => s.ThenInclude(navigationPropertyPath));
/// <summary> /// Creates and emits a <see cref="T:System.Collections.Generic.List`1"></see> /// from an <see cref="T:System.Collections.Generic.IEnumerable`1"></see>. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <returns>An instance of <see cref="IProviderObservable{List}"/>.</returns> public static IProviderObservable <List <TSource> > ToList <TSource>( this IProviderObservable <IEnumerable <TSource> > observable) => observable.Map(s => s.ToList());
/// <summary> /// <para> /// Returns a new query where the change tracker will not track any of the entities /// that are returned. If the entity instances are modified, this will not be /// detected by the change tracker and /// <see cref="M:Microsoft.EntityFrameworkCore.DbContext.SaveChanges" /> will not /// persist those changes to the database. /// </para> /// <para> /// Disabling change tracking is useful for read-only scenarios because it avoids /// the overhead of setting up change tracking for each entity instance. You should /// not disable change tracking if you want to manipulate entity instances and /// persist those changes to the database using /// <see cref="M:Microsoft.EntityFrameworkCore.DbContext.SaveChanges" />. /// </para> /// <para> /// Identity resolution will still be performed to ensure that all occurrences of /// an entity with a given key in the result set are represented by the same entity /// instance. /// </para> /// <para> /// The default tracking behavior for queries can be controlled by /// <see cref="P:Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.QueryTrackingBehavior" />. /// </para> /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <returns>An instance of <see cref="IProviderObservable{TSource}"/>.</returns> public static IProviderObservable <IQueryable <TSource> > AsNoTracking <TSource>( this IProviderObservable <IQueryable <TSource> > observable) where TSource : class => observable.Map(s => s.AsNoTracking());
/// <summary> /// Filters a sequence of values based on a predicate. /// Each element's index is used in the logic of the predicate function. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="predicate"> /// A function to test each element for a condition; the second /// parameter of the function represents the index of the element in the source sequence. /// </param> /// <returns>An instance of <see cref="IProviderObservable{IQueryable}"/>.</returns> public static IProviderObservable <IQueryable <TSource> > Where <TSource>( this IProviderObservable <IQueryable <TSource> > observable, Expression <Func <TSource, int, bool> > predicate) => observable.Map(s => s.Where(predicate));
/// <summary> /// Sorts the elements of a sequence in ascending order by using a specified comparer. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <typeparam name="TKey">The type of the key.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="keySelector">A function to extract a key from an element.</param> /// <param name="comparer"> /// An <see cref="T:System.Collections.Generic.IComparer`1"></see> to compare keys. /// </param> /// <returns>An instance of <see cref="IProviderObservable{IOrderedQueryable}"/>.</returns> public static IProviderObservable <IOrderedQueryable <TSource> > OrderBy <TSource, TKey>( this IProviderObservable <IQueryable <TSource> > observable, Expression <Func <TSource, TKey> > keySelector, IComparer <TKey> comparer) => observable.Map(s => s.OrderBy(keySelector, comparer));
/// <summary> /// Performs a subsequent ordering of the elements in a sequence /// in ascending order according to a key. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <typeparam name="TKey">The type of the key.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="keySelector">A function to extract a key from an element.</param> /// <returns>An instance of <see cref="IProviderObservable{IOrderedQueryable}"/>.</returns> public static IProviderObservable <IOrderedQueryable <TSource> > ThenBy <TSource, TKey>( this IProviderObservable <IOrderedQueryable <TSource> > observable, Expression <Func <TSource, TKey> > keySelector) => observable.Map(s => s.ThenBy(keySelector));
/// <summary> /// Emits the only element of a sequence, and throws an exception /// if there is not exactly one element in the sequence. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <param name="observable">The parent observable.</param> /// <returns>An instance of <see cref="IProviderObservable{TSource}"/>.</returns> public static IProviderObservable <TSource> Single <TSource>( this IProviderObservable <IQueryable <TSource> > observable) => observable.Map(s => s.Single());
/// <summary> /// Sorts the elements of a sequence in descending order according to a key. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <typeparam name="TKey">The type of the key.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="keySelector">A function to extract a key from an element.</param> /// <returns>An instance of <see cref="IProviderObservable{IOrderedQueryable}"/>.</returns> public static IProviderObservable <IOrderedQueryable <TSource> > OrderByDescending <TSource, TKey>( this IProviderObservable <IQueryable <TSource> > observable, Expression <Func <TSource, TKey> > keySelector) => observable.Map(s => s.OrderByDescending(keySelector));
/// <summary> /// Performs a subsequent ordering of the elements in a sequence /// in descending order by using a specified comparer. /// </summary> /// <typeparam name="TSource">The type of the value.</typeparam> /// <typeparam name="TKey">The type of the key.</typeparam> /// <param name="observable">The parent observable.</param> /// <param name="keySelector">A function to extract a key from an element.</param> /// <param name="comparer"> /// An <see cref="T:System.Collections.Generic.IComparer`1"></see> to compare keys. /// </param> /// <returns>An instance of <see cref="IProviderObservable{IOrderedQueryable}"/>.</returns> public static IProviderObservable <IOrderedQueryable <TSource> > ThenByDescending <TSource, TKey>( this IProviderObservable <IOrderedQueryable <TSource> > observable, Expression <Func <TSource, TKey> > keySelector, IComparer <TKey> comparer) => observable.Map(s => s.ThenByDescending(keySelector, comparer));