This repository was archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEntityRepository.cs
59 lines (48 loc) · 2.26 KB
/
EntityRepository.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
namespace Monstarlab.EntityFramework.Extension.Repositories;
public class EntityRepository<TContext, TEntity, TId> : BaseEntityRepository<TContext, TEntity, TId>, IEntityRepository<TEntity, TId>
where TContext : DbContext
where TEntity : EntityBase<TId>
{
public EntityRepository(TContext context) : base(context) { }
public Task<TEntity?> GetAsync(Expression<Func<TEntity, bool>> where)
=> BaseIncludes().FirstOrDefaultAsync(where);
public virtual Task<ListWrapper<TEntity>> GetListAsync(
[Range(1, int.MaxValue)] int page,
[Range(1, int.MaxValue)] int pageSize,
Expression<Func<TEntity, bool>>[] where = null,
Expression<Func<TEntity, object>> orderByExpression = null,
OrderBy orderBy = OrderBy.Ascending)
{
var query = GetQueryable(where, orderByExpression, orderBy);
return GetListAsync(query, page, pageSize);
}
public virtual Task<ListWrapper<TResult>> GetListWithSelectAsync<TResult>(
Expression<Func<TEntity, TResult>> select,
[Range(1, int.MaxValue)] int page,
[Range(1, int.MaxValue)] int pageSize,
Expression<Func<TEntity, bool>>[] where = null,
Expression<Func<TEntity, object>> orderByExpression = null,
OrderBy orderBy = OrderBy.Ascending)
{
var query = GetQueryable(where, orderByExpression, orderBy);
var selectedQuery = query.Select(select);
return GetListAsync(selectedQuery, page, pageSize);
}
public virtual async Task<IEnumerable<TEntity>> GetListAsync(
Expression<Func<TEntity, bool>>[] where = null,
Expression<Func<TEntity, object>> orderByExpression = null,
OrderBy orderBy = OrderBy.Ascending)
{
var query = GetQueryable(where, orderByExpression, orderBy);
return await query.ToListAsync();
}
public virtual async Task<IEnumerable<TResult>> GetListWithSelectAsync<TResult>(
Expression<Func<TEntity, TResult>> select,
Expression<Func<TEntity, bool>>[] where = null,
Expression<Func<TEntity, object>> orderByExpression = null,
OrderBy orderBy = OrderBy.Ascending)
{
var query = GetQueryable(where, orderByExpression, orderBy);
return await query.Select(select).ToListAsync();
}
}