7
7
8
8
namespace Core . DataAccess . EntityFramework
9
9
{
10
- public class EfEntityRepositoryBase < TEntity , TContext > : IEntityRepository < TEntity >
11
- where TEntity : class , IEntity , new ( )
12
- where TContext : DbContext , new ( )
10
+ public class EfEntityRepositoryBase < TEntity , TContext > : IEntityRepository < TEntity >
11
+ where TEntity : class , IEntity , new ( )
12
+ where TContext : DbContext , new ( )
13
13
{
14
14
public List < TEntity > GetAll ( Expression < Func < TEntity , bool > > filter = null )
15
15
{
16
- using ( TContext context = new TContext ( ) )
16
+ using ( var context = new TContext ( ) )
17
17
{
18
18
return filter == null ? context . Set < TEntity > ( ) . ToList ( ) : context . Set < TEntity > ( ) . Where ( filter ) . ToList ( ) ;
19
19
}
20
20
}
21
21
22
22
public TEntity Get ( Expression < Func < TEntity , bool > > filter )
23
23
{
24
- using ( TContext context = new TContext ( ) )
24
+ using ( var context = new TContext ( ) )
25
25
{
26
26
return context . Set < TEntity > ( ) . SingleOrDefault ( filter ) ;
27
27
}
28
28
}
29
29
30
30
public void Add ( TEntity entity )
31
31
{
32
- using ( TContext context = new TContext ( ) )
32
+ using ( var context = new TContext ( ) )
33
33
{
34
34
var addedEntity = context . Entry ( entity ) ;
35
35
addedEntity . State = EntityState . Added ;
@@ -39,16 +39,17 @@ public void Add(TEntity entity)
39
39
40
40
public void Update ( TEntity entity )
41
41
{
42
- using ( TContext context = new TContext ( ) )
42
+ using ( var context = new TContext ( ) )
43
43
{
44
44
var updatedEntity = context . Entry ( entity ) ;
45
45
updatedEntity . State = EntityState . Modified ;
46
46
context . SaveChanges ( ) ;
47
- } }
47
+ }
48
+ }
48
49
49
50
public void Delete ( TEntity entity )
50
51
{
51
- using ( TContext context = new TContext ( ) )
52
+ using ( var context = new TContext ( ) )
52
53
{
53
54
var deletedEntity = context . Entry ( entity ) ;
54
55
deletedEntity . State = EntityState . Deleted ;
0 commit comments