/// <summary> /// Gets model of type T from repository by identifier. /// If no entity is found, then null is returned. /// </summary> /// <typeparam name="TModel">The type of the T model.</typeparam> /// <typeparam name="TEntity">The type of the T entity.</typeparam> /// <typeparam name="TKey">The type of the T key.</typeparam> /// <param name="repository">The repository.</param> /// <param name="id">The identifier.</param> /// <returns><cref>TModel</cref></returns> public static TModel Get <TModel, TEntity, TKey>(this IRepository <TEntity, TKey> repository, TKey id) where TEntity : class, IEntity <TKey> { return(repository.Get <TModel, TEntity, TKey>( FilterExpressionExtensions.CreateIdFilterExpression <TEntity, TKey>(id) )); }
/// <summary> /// Checks if entity of type T with identifier exists in repository. /// </summary> /// <typeparam name="TEntity">The type of the T entity.</typeparam> /// <typeparam name="TKey">The type of the T key.</typeparam> /// <param name="repository">The repository.</param> /// <param name="id">The identifier.</param> /// <returns><c>true</c> if exists, <c>false</c> otherwise.</returns> public static bool Exists <TEntity, TKey>(this IRepository <TEntity, TKey> repository, TKey id) where TEntity : class, IEntity <TKey> { return(repository.Exists( FilterExpressionExtensions.CreateIdFilterExpression <TEntity, TKey>(id) )); }
/// <summary> /// Asynchronously checks if entity of type T with identifier exists in repository. /// </summary> /// <typeparam name="TEntity">The type of the T entity.</typeparam> /// <typeparam name="TKey">The type of the T key.</typeparam> /// <param name="repository">The repository.</param> /// <param name="id">The identifier.</param> /// <returns><c>true</c> if exists, <c>false</c> otherwise.</returns> public static async Task <bool> ExistsAsync <TEntity, TKey>( this IRepository <TEntity, TKey> repository, TKey id) where TEntity : class, IEntity <TKey> { return(await repository.ExistsAsync( FilterExpressionExtensions.CreateIdFilterExpression <TEntity, TKey>(id) )); }
/// <summary> /// Asynchronously gets model of type T from repository by identifier. /// If no entity is found, then null is returned. /// </summary> /// <typeparam name="TModel">The type of the T model.</typeparam> /// <typeparam name="TEntity">The type of the T entity.</typeparam> /// <typeparam name="TKey">The type of the T key.</typeparam> /// <param name="repository">The repository.</param> /// <param name="id">The identifier.</param> /// <returns><cref>Task{TModel}</cref>.</returns> public static async Task <TModel> GetAsync <TModel, TEntity, TKey>( this IRepository <TEntity, TKey> repository, TKey id) where TEntity : class, IEntity <TKey> { return(await repository.GetAsync <TModel, TEntity, TKey>( FilterExpressionExtensions.CreateIdFilterExpression <TEntity, TKey>(id) )); }