mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-27 08:00:52 +08:00
fix: try for fix DbUpdateConcurrencyException
This commit is contained in:
parent
c09f854b28
commit
6dffdfb779
@ -13,6 +13,7 @@ using global::Polly;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Exception = System.Exception;
|
||||||
|
|
||||||
public abstract class AppDbContextBase : DbContext, IDbContext
|
public abstract class AppDbContextBase : DbContext, IDbContext
|
||||||
{
|
{
|
||||||
@ -82,6 +83,7 @@ public abstract class AppDbContextBase : DbContext, IDbContext
|
|||||||
//ref: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=fluent-api#resolving-concurrency-conflicts
|
//ref: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=fluent-api#resolving-concurrency-conflicts
|
||||||
catch (DbUpdateConcurrencyException ex)
|
catch (DbUpdateConcurrencyException ex)
|
||||||
{
|
{
|
||||||
|
throw new DbUpdateConcurrencyException("try for get unhandled exception with DbUpdateConcurrencyException", ex);
|
||||||
var logger = _httpContextAccessor?.HttpContext?.RequestServices
|
var logger = _httpContextAccessor?.HttpContext?.RequestServices
|
||||||
.GetRequiredService<ILogger<AppDbContextBase>>();
|
.GetRequiredService<ILogger<AppDbContextBase>>();
|
||||||
|
|
||||||
@ -116,6 +118,10 @@ public abstract class AppDbContextBase : DbContext, IDbContext
|
|||||||
|
|
||||||
return await policy.ExecuteAsync(async () => await base.SaveChangesAsync(cancellationToken));
|
return await policy.ExecuteAsync(async () => await base.SaveChangesAsync(cancellationToken));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("try for get unhandled exception bt default", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<IDomainEvent> GetDomainEvents()
|
public IReadOnlyList<IDomainEvent> GetDomainEvents()
|
||||||
@ -138,6 +144,8 @@ public abstract class AppDbContextBase : DbContext, IDbContext
|
|||||||
// ref: https://www.meziantou.net/entity-framework-core-generate-tracking-columns.htm
|
// ref: https://www.meziantou.net/entity-framework-core-generate-tracking-columns.htm
|
||||||
// ref: https://www.meziantou.net/entity-framework-core-soft-delete-using-query-filters.htm
|
// ref: https://www.meziantou.net/entity-framework-core-soft-delete-using-query-filters.htm
|
||||||
private void OnBeforeSaving()
|
private void OnBeforeSaving()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
foreach (var entry in ChangeTracker.Entries<IAggregate>())
|
foreach (var entry in ChangeTracker.Entries<IAggregate>())
|
||||||
{
|
{
|
||||||
@ -170,6 +178,11 @@ public abstract class AppDbContextBase : DbContext, IDbContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("try for find IAggregate", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private long? GetCurrentUserId()
|
private long? GetCurrentUserId()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user