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

Commit bae43db

Browse files
committed
WIP: Metodi CRUD con Transaction
1 parent 50d37d9 commit bae43db

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/NET6CustomLibrary/EFCore/Core/Command.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,60 @@ public async Task DeleteAsync(TEntity entity)
3333

3434
await DbContext.SaveChangesAsync();
3535
}
36+
37+
//public async Task CreateTransactionAsync(TEntity entity)
38+
//{
39+
// using var transaction = await DbContext.Database.BeginTransactionAsync();
40+
41+
// try
42+
// {
43+
// DbContext.Set<TEntity>().Add(entity);
44+
// await DbContext.SaveChangesAsync();
45+
// DbContext.Entry(entity).State = EntityState.Detached;
46+
47+
// await transaction.CommitAsync();
48+
// }
49+
// catch (Exception)
50+
// {
51+
// await transaction.RollbackAsync();
52+
// throw;
53+
// }
54+
//}
55+
56+
//public async Task UpdateTransactionAsync(TEntity entity)
57+
//{
58+
// using var transaction = await DbContext.Database.BeginTransactionAsync();
59+
60+
// try
61+
// {
62+
// DbContext.Set<TEntity>().Update(entity);
63+
// await DbContext.SaveChangesAsync();
64+
// DbContext.Entry(entity).State = EntityState.Detached;
65+
66+
// transaction.Commit();
67+
// }
68+
// catch (Exception)
69+
// {
70+
// await transaction.RollbackAsync();
71+
// throw;
72+
// }
73+
//}
74+
75+
//public async Task DeleteTransactionAsync(TEntity entity)
76+
//{
77+
// using var transaction = await DbContext.Database.BeginTransactionAsync();
78+
79+
// try
80+
// {
81+
// DbContext.Set<TEntity>().Remove(entity);
82+
// await DbContext.SaveChangesAsync();
83+
84+
// transaction.Commit();
85+
// }
86+
// catch (Exception)
87+
// {
88+
// await transaction.RollbackAsync();
89+
// throw;
90+
// }
91+
//}
3692
}

src/NET6CustomLibrary/EFCore/Core/Interfaces/ICommand.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@
2222
/// <param name="entity"></param>
2323
/// <returns></returns>
2424
Task DeleteAsync(TEntity entity);
25+
26+
//Task CreateTransactionAsync(TEntity entity);
27+
28+
//Task UpdateTransactionAsync(TEntity entity);
29+
30+
//Task DeleteTransactionAsync(TEntity entity);
2531
}

0 commit comments

Comments
 (0)