mirror of https://github.com/abpframework/abp.git
21 changed files with 230 additions and 130 deletions
@ -0,0 +1,7 @@ |
|||||
|
namespace AbpDesk.Tickets.Dtos |
||||
|
{ |
||||
|
public class GetAllTicketsInput |
||||
|
{ |
||||
|
public string Filter { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
namespace Volo.Abp.Application.Services.Dtos |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// This interface is defined to standardize to request a limited result.
|
||||
|
/// </summary>
|
||||
|
public interface ILimitedResultRequest |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Max expected result count.
|
||||
|
/// </summary>
|
||||
|
int MaxResultCount { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
namespace Volo.Abp.Application.Services.Dtos |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// This interface is defined to standardize to request a paged result.
|
||||
|
/// </summary>
|
||||
|
public interface IPagedResultRequest : ILimitedResultRequest |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Skip count (beginning of the page).
|
||||
|
/// </summary>
|
||||
|
int SkipCount { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
using System; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.Abp.Repositories.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.Repositories |
||||
|
{ |
||||
|
public static class EfCoreRepositoryExtensions |
||||
|
{ |
||||
|
public static DbContext GetDbContext<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository) |
||||
|
where TEntity : class, IEntity<TPrimaryKey>, new() |
||||
|
{ |
||||
|
var efCoreRepository = repository as IEfCoreRepository; |
||||
|
if (efCoreRepository == null) |
||||
|
{ |
||||
|
throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository).AssemblyQualifiedName, nameof(repository)); |
||||
|
} |
||||
|
|
||||
|
return efCoreRepository.DbContext; |
||||
|
} |
||||
|
|
||||
|
public static DbSet<TEntity> GetDbSet<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository) |
||||
|
where TEntity : class, IEntity<TPrimaryKey>, new() |
||||
|
{ |
||||
|
var efCoreRepository = repository as IEfCoreRepository<TEntity, TPrimaryKey>; |
||||
|
if (efCoreRepository == null) |
||||
|
{ |
||||
|
throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository<TEntity, TPrimaryKey>).AssemblyQualifiedName, nameof(repository)); |
||||
|
} |
||||
|
|
||||
|
return efCoreRepository.DbSet; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
|
||||
|
namespace Volo.Abp.Repositories.EntityFrameworkCore |
||||
|
{ |
||||
|
public interface IEfCoreRepository |
||||
|
{ |
||||
|
DbContext DbContext { get; } |
||||
|
} |
||||
|
|
||||
|
public interface IEfCoreRepository<TEntity, TPrimaryKey> : IEfCoreRepository |
||||
|
where TEntity : class, IEntity<TPrimaryKey> |
||||
|
{ |
||||
|
DbSet<TEntity> DbSet { get; } |
||||
|
} |
||||
|
} |
||||
@ -1,7 +0,0 @@ |
|||||
namespace Volo.Abp.Domain.Repositories |
|
||||
{ |
|
||||
public interface IRepositoryMarker |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,68 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Expressions; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.Application.Services.Dtos; |
||||
|
|
||||
|
namespace Volo.Abp.Linq.Extensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Some useful extension methods for <see cref="IQueryable{T}"/>.
|
||||
|
/// </summary>
|
||||
|
public static class QueryableExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Used for paging. Can be used as an alternative to Skip(...).Take(...) chaining.
|
||||
|
/// </summary>
|
||||
|
public static IQueryable<T> PageBy<T>([NotNull] this IQueryable<T> query, int skipCount, int maxResultCount) |
||||
|
{ |
||||
|
Check.NotNull(query, nameof(query)); |
||||
|
|
||||
|
return query.Skip(skipCount).Take(maxResultCount); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Used for paging with an <see cref="IPagedResultRequest"/> object.
|
||||
|
/// </summary>
|
||||
|
/// <param name="query">Queryable to apply paging</param>
|
||||
|
/// <param name="pagedResultRequest">An object implements <see cref="IPagedResultRequest"/> interface</param>
|
||||
|
public static IQueryable<T> PageBy<T>([NotNull] this IQueryable<T> query, IPagedResultRequest pagedResultRequest) |
||||
|
{ |
||||
|
Check.NotNull(query, nameof(query)); |
||||
|
|
||||
|
return query.PageBy(pagedResultRequest.SkipCount, pagedResultRequest.MaxResultCount); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Filters a <see cref="IQueryable{T}"/> by given predicate if given condition is true.
|
||||
|
/// </summary>
|
||||
|
/// <param name="query">Queryable to apply filtering</param>
|
||||
|
/// <param name="condition">A boolean value</param>
|
||||
|
/// <param name="predicate">Predicate to filter the query</param>
|
||||
|
/// <returns>Filtered or not filtered query based on <paramref name="condition"/></returns>
|
||||
|
public static IQueryable<T> WhereIf<T>([NotNull] this IQueryable<T> query, bool condition, Expression<Func<T, bool>> predicate) |
||||
|
{ |
||||
|
Check.NotNull(query, nameof(query)); |
||||
|
|
||||
|
return condition |
||||
|
? query.Where(predicate) |
||||
|
: query; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Filters a <see cref="IQueryable{T}"/> by given predicate if given condition is true.
|
||||
|
/// </summary>
|
||||
|
/// <param name="query">Queryable to apply filtering</param>
|
||||
|
/// <param name="condition">A boolean value</param>
|
||||
|
/// <param name="predicate">Predicate to filter the query</param>
|
||||
|
/// <returns>Filtered or not filtered query based on <paramref name="condition"/></returns>
|
||||
|
public static IQueryable<T> WhereIf<T>([NotNull] this IQueryable<T> query, bool condition, Expression<Func<T, int, bool>> predicate) |
||||
|
{ |
||||
|
Check.NotNull(query, nameof(query)); |
||||
|
|
||||
|
return condition |
||||
|
? query.Where(predicate) |
||||
|
: query; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue