@@ -5,16 +5,16 @@ public class Repository<TDbContext, TEntity> :
5
5
where TEntity : class , IEntity
6
6
where TDbContext : DbContext
7
7
{
8
- protected readonly TDbContext _context ;
8
+ protected readonly TDbContext Context ;
9
9
10
10
public Repository ( TDbContext context , IUnitOfWork unitOfWork )
11
11
{
12
- _context = context ;
12
+ Context = context ;
13
13
UnitOfWork = unitOfWork ;
14
14
}
15
15
16
16
public override bool TransactionHasBegun
17
- => _context . Database . CurrentTransaction != null ;
17
+ => Context . Database . CurrentTransaction != null ;
18
18
19
19
public override DbTransaction Transaction
20
20
{
@@ -24,9 +24,9 @@ public override DbTransaction Transaction
24
24
throw new NotSupportedException ( nameof ( Transaction ) ) ;
25
25
26
26
if ( TransactionHasBegun )
27
- return _context . Database . CurrentTransaction ! . GetDbTransaction ( ) ;
27
+ return Context . Database . CurrentTransaction ! . GetDbTransaction ( ) ;
28
28
29
- return _context . Database . BeginTransaction ( ) . GetDbTransaction ( ) ;
29
+ return Context . Database . BeginTransaction ( ) . GetDbTransaction ( ) ;
30
30
}
31
31
}
32
32
@@ -53,7 +53,7 @@ public override async ValueTask<TEntity> AddAsync(
53
53
TEntity entity ,
54
54
CancellationToken cancellationToken = default )
55
55
{
56
- var response = ( await _context . AddAsync ( entity , cancellationToken ) . AsTask ( ) ) . Entity ;
56
+ var response = ( await Context . AddAsync ( entity , cancellationToken ) . AsTask ( ) ) . Entity ;
57
57
EntityState = EntityState . Changed ;
58
58
return response ;
59
59
}
@@ -62,45 +62,45 @@ public override async Task AddRangeAsync(
62
62
IEnumerable < TEntity > entities ,
63
63
CancellationToken cancellationToken = default )
64
64
{
65
- await _context . AddRangeAsync ( entities , cancellationToken ) ;
65
+ await Context . AddRangeAsync ( entities , cancellationToken ) ;
66
66
EntityState = EntityState . Changed ;
67
67
}
68
68
69
69
public override Task CommitAsync ( CancellationToken cancellationToken = default )
70
70
=> UnitOfWork . CommitAsync ( cancellationToken ) ;
71
71
72
- public override async ValueTask DisposeAsync ( ) => await _context . DisposeAsync ( ) ;
72
+ public override async ValueTask DisposeAsync ( ) => await Context . DisposeAsync ( ) ;
73
73
74
- public override void Dispose ( ) => _context . Dispose ( ) ;
74
+ public override void Dispose ( ) => Context . Dispose ( ) ;
75
75
76
76
public override Task < TEntity ? > FindAsync (
77
77
IEnumerable < KeyValuePair < string , object > > keyValues ,
78
78
CancellationToken cancellationToken = default )
79
79
{
80
80
Dictionary < string , object > fields = new ( keyValues ) ;
81
- return _context . Set < TEntity > ( ) . IgnoreQueryFilters ( ) . GetQueryable ( fields ) . FirstOrDefaultAsync ( cancellationToken ) ;
81
+ return Context . Set < TEntity > ( ) . IgnoreQueryFilters ( ) . GetQueryable ( fields ) . FirstOrDefaultAsync ( cancellationToken ) ;
82
82
}
83
83
84
84
public override Task < TEntity ? > FindAsync (
85
85
Expression < Func < TEntity , bool > > predicate ,
86
86
CancellationToken cancellationToken = default )
87
- => _context . Set < TEntity > ( ) . Where ( predicate ) . FirstOrDefaultAsync ( cancellationToken ) ;
87
+ => Context . Set < TEntity > ( ) . Where ( predicate ) . FirstOrDefaultAsync ( cancellationToken ) ;
88
88
89
89
public override async Task < long > GetCountAsync ( CancellationToken cancellationToken = default )
90
- => await _context . Set < TEntity > ( ) . LongCountAsync ( cancellationToken ) ;
90
+ => await Context . Set < TEntity > ( ) . LongCountAsync ( cancellationToken ) ;
91
91
92
92
public override Task < long > GetCountAsync (
93
93
Expression < Func < TEntity , bool > > predicate ,
94
94
CancellationToken cancellationToken = default )
95
- => _context . Set < TEntity > ( ) . LongCountAsync ( predicate , cancellationToken ) ;
95
+ => Context . Set < TEntity > ( ) . LongCountAsync ( predicate , cancellationToken ) ;
96
96
97
97
public override async Task < IEnumerable < TEntity > > GetListAsync ( CancellationToken cancellationToken = default )
98
- => await _context . Set < TEntity > ( ) . ToListAsync ( cancellationToken ) ;
98
+ => await Context . Set < TEntity > ( ) . ToListAsync ( cancellationToken ) ;
99
99
100
100
public override async Task < IEnumerable < TEntity > > GetListAsync (
101
101
Expression < Func < TEntity , bool > > predicate ,
102
102
CancellationToken cancellationToken = default )
103
- => await _context . Set < TEntity > ( ) . Where ( predicate ) . ToListAsync ( cancellationToken ) ;
103
+ => await Context . Set < TEntity > ( ) . Where ( predicate ) . ToListAsync ( cancellationToken ) ;
104
104
105
105
/// <summary>
106
106
///
@@ -118,7 +118,7 @@ public override Task<List<TEntity>> GetPaginatedListAsync(
118
118
{
119
119
sorting ??= new Dictionary < string , bool > ( ) ;
120
120
121
- return _context . Set < TEntity > ( ) . OrderBy ( sorting ) . Skip ( skip ) . Take ( take ) . ToListAsync ( cancellationToken ) ;
121
+ return Context . Set < TEntity > ( ) . OrderBy ( sorting ) . Skip ( skip ) . Take ( take ) . ToListAsync ( cancellationToken ) ;
122
122
}
123
123
124
124
/// <summary>
@@ -139,12 +139,12 @@ public override Task<List<TEntity>> GetPaginatedListAsync(
139
139
{
140
140
sorting ??= new Dictionary < string , bool > ( ) ;
141
141
142
- return _context . Set < TEntity > ( ) . Where ( predicate ) . OrderBy ( sorting ) . Skip ( skip ) . Take ( take ) . ToListAsync ( cancellationToken ) ;
142
+ return Context . Set < TEntity > ( ) . Where ( predicate ) . OrderBy ( sorting ) . Skip ( skip ) . Take ( take ) . ToListAsync ( cancellationToken ) ;
143
143
}
144
144
145
145
public override Task < TEntity > RemoveAsync ( TEntity entity , CancellationToken cancellationToken = default )
146
146
{
147
- _context . Set < TEntity > ( ) . Remove ( entity ) ;
147
+ Context . Set < TEntity > ( ) . Remove ( entity ) ;
148
148
EntityState = EntityState . Changed ;
149
149
return Task . FromResult ( entity ) ;
150
150
}
@@ -153,12 +153,12 @@ public override async Task RemoveAsync(Expression<Func<TEntity, bool>> predicate
153
153
{
154
154
var entities = await GetListAsync ( predicate , cancellationToken ) ;
155
155
EntityState = EntityState . Changed ;
156
- _context . Set < TEntity > ( ) . RemoveRange ( entities ) ;
156
+ Context . Set < TEntity > ( ) . RemoveRange ( entities ) ;
157
157
}
158
158
159
159
public override Task RemoveRangeAsync ( IEnumerable < TEntity > entities , CancellationToken cancellationToken = default )
160
160
{
161
- _context . Set < TEntity > ( ) . RemoveRange ( entities ) ;
161
+ Context . Set < TEntity > ( ) . RemoveRange ( entities ) ;
162
162
EntityState = EntityState . Changed ;
163
163
return Task . CompletedTask ;
164
164
}
@@ -173,14 +173,14 @@ public override async Task SaveChangesAsync(CancellationToken cancellationToken
173
173
174
174
public override Task < TEntity > UpdateAsync ( TEntity entity , CancellationToken cancellationToken = default )
175
175
{
176
- _context . Set < TEntity > ( ) . Update ( entity ) ;
176
+ Context . Set < TEntity > ( ) . Update ( entity ) ;
177
177
EntityState = EntityState . Changed ;
178
178
return Task . FromResult ( entity ) ;
179
179
}
180
180
181
181
public override Task UpdateRangeAsync ( IEnumerable < TEntity > entities , CancellationToken cancellationToken = default )
182
182
{
183
- _context . Set < TEntity > ( ) . UpdateRange ( entities ) ;
183
+ Context . Set < TEntity > ( ) . UpdateRange ( entities ) ;
184
184
EntityState = EntityState . Changed ;
185
185
return Task . CompletedTask ;
186
186
}
@@ -213,5 +213,5 @@ public Repository(TDbContext context, IUnitOfWork unitOfWork) : base(context, un
213
213
}
214
214
215
215
public Task < TEntity ? > FindAsync ( TKey id )
216
- => _context . Set < TEntity > ( ) . FirstOrDefaultAsync ( entity => entity . Id . Equals ( id ) ) ;
216
+ => Context . Set < TEntity > ( ) . FirstOrDefaultAsync ( entity => entity . Id . Equals ( id ) ) ;
217
217
}
0 commit comments