feat(dal): тестирование CommitAsync() с отслеживанием изменений

This commit is contained in:
Mikhail Trubnikov
2024-10-03 16:38:21 +10:00
parent 79a10dc927
commit 5c03b6bc81
2 changed files with 88 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.DomainModels;
using PARR.DAL.Models;
using PARR.DAL.Models.Base;
using PARR.DAL.Services.Interfaces.Base;
@@ -37,6 +38,40 @@ namespace PARR.DAL.Services.Abstracts
public async Task<bool> CommitAsync()
{
#region test
////https://stackoverflow.com/questions/53064528/entityframework-core-get-changes-occured-in-entity-and-related-data
//var modifiedEntrities = EntitiContext.ChangeTracker.Entries()
// .Where(t => t.State == EntityState.Modified || t.State == EntityState.Deleted);
//foreach (var change in modifiedEntrities)
//{
// ////var type = change.Entity.GetType();
// ////var userType = typeof(User);
// if (change.Entity.GetType() == typeof(User))
// {
// // это пользователь
// var user = change.Entity as User;
// if (user!.Name == "string")
// {
// //user.LastLogon = DateTimeOffset.UtcNow;
// user.Description = "Новый description " + DateTime.Now.Microsecond;
// }
// }
// // интерфейс IBase?
// //if (change.Entity.GetType().IsAssignableFrom(typeof(IBase)))
// if (change.Entity.GetType().GetInterface(nameof(IBase)) != null)
// {
// (change.Entity as IBase)!.DateModified = DateTimeOffset.UtcNow;
// }
//}
#endregion
try
{
await EntitiContext.SaveChangesAsync();