Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 058e7c1

Browse files
author
Morten Turn Pedersen
committed
Add disposable methods
1 parent dda2fea commit 058e7c1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

NetCoreEntityFramework/NetCoreEntityFramework.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<PackageId>Nodes.NetCore.EntityFramework.Helpers</PackageId>
6-
<Version>0.1.0</Version>
6+
<Version>0.1.1</Version>
77
<Authors>Nodes</Authors>
88
<Company>Nodes</Company>
99
<Product>.NET Core Entity Framework Helpers</Product>

NetCoreEntityFramework/Repositories/EntityRepository.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@
55

66
namespace Nodes.NetCore.EntityFramework.Repositories
77
{
8-
public abstract class EntityRepository<T> where T : EntityBase
8+
public abstract class EntityRepository<T, TContext> : IDisposable where T : EntityBase where TContext : DbContext
99
{
1010
protected DbSet<T> Table { get; private set; }
11+
private TContext Context { get; set; }
1112

12-
protected EntityRepository(DbSet<T> table)
13+
protected EntityRepository(TContext context, DbSet<T> table)
1314
{
15+
Context = context;
1416
Table = table;
1517
}
1618

1719
public async Task<T> Get(Guid id)
1820
{
1921
return await Table.FirstOrDefaultAsync(entity => !entity.Deleted && entity.Id == id);
2022
}
23+
24+
public void Dispose()
25+
{
26+
Context.SaveChanges();
27+
}
2128
}
2229
}

0 commit comments

Comments
 (0)