Compare commits

...

3 Commits

Author SHA1 Message Date
0cf6d2690a chore(Infrastructure): bump to 2.5.0 2025-11-05 14:22:22 +01:00
afbbac7b81 core(Abstraction.Application): bump to 1.5.0 2025-11-05 14:21:29 +01:00
d16a4b6bb4 refactor(repository): make UpdateAsync more flexible with Action<TEntity>
- Introduced Action<TEntity>-based UpdateAsync method for more flexible updates
- Updated TDto-based UpdateAsync to delegate to the new method
- Reduced code duplication and Mapper dependency
- Preserved existing Create, Read, and Delete functionality
2025-11-05 14:20:12 +01:00
4 changed files with 129 additions and 117 deletions

View File

@ -12,9 +12,9 @@
<PackageIcon>core_icon.png</PackageIcon>
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
<PackageTags>digital data core application clean architecture abstraction</PackageTags>
<Version>1.4.0</Version>
<AssemblyVersion>1.4.0</AssemblyVersion>
<FileVersion>1.4.0</FileVersion>
<Version>1.5.0</Version>
<AssemblyVersion>1.5.0</AssemblyVersion>
<FileVersion>1.5.0</FileVersion>
</PropertyGroup>
<ItemGroup>

View File

@ -1,5 +1,4 @@
using DigitalData.Core.Abstractions.Interfaces;
using System.Linq.Expressions;
using System.Linq.Expressions;
#if NETFRAMEWORK
using System;
using System.Collections.Generic;
@ -15,8 +14,8 @@ namespace DigitalData.Core.Abstraction.Application.Repository
{
#endif
public interface IRepository<TEntity>
{
public interface IRepository<TEntity>
{
#region Create
#if NET
public
@ -71,6 +70,16 @@ public interface IRepository<TEntity>
public
#endif
Task UpdateAsync<TDto>(TDto dto, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default);
#if NET
public
#endif
Task UpdateAsync(Action<TEntity> modification, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default);
#if NET
public
#endif
Task UpdateAsync(Action<TEntity> modification, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default);
#endregion Update
#region Delete
@ -98,7 +107,7 @@ public interface IRepository<TEntity>
#endif
IQueryable<TEntity> ReadOnly();
#endregion
}
}
#if NETFRAMEWORK
}
#endif

View File

@ -21,8 +21,8 @@ namespace DigitalData.Core.Infrastructure
{
#endif
public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbContext : DbContext where TEntity : class
{
public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbContext : DbContext where TEntity : class
{
protected internal readonly TDbContext Context;
protected internal readonly DbSet<TEntity> Entities;
@ -87,22 +87,25 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
#region Update
public virtual Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default) => UpdateAsync(dto, q => q.Where(expression), cancel);
public virtual async Task UpdateAsync<TDto>(TDto dto, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default)
public virtual Task UpdateAsync<TDto>(TDto dto, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default)
=> UpdateAsync(entity => Mapper
#if NET
!
#endif
.Map(dto, entity), query, cancel);
public virtual async Task UpdateAsync(Action<TEntity> modification, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default)
{
var entities = await query(Entities).ToListAsync(cancel);
for (int i = entities.Count - 1; i >= 0; i--)
{
Mapper
#if NET
!
#endif
.Map(dto, entities[i]);
Entities.Update(entities[i]);
}
modification.Invoke(entities[i]);
await Context.SaveChangesAsync(cancel);
}
public virtual Task UpdateAsync(Action<TEntity> modification, Expression<Func<TEntity, bool>> expression, CancellationToken cancel = default)
=> UpdateAsync(modification, q => q.Where(expression), cancel);
#endregion Update
#region Delete
@ -128,7 +131,7 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
[Obsolete("Use IRepository<TEntity>.Get")]
public virtual IQueryable<TEntity> ReadOnly() => Entities.AsNoTracking();
#endregion
}
}
#if NETFRAMEWORK
}
#endif

View File

@ -13,9 +13,9 @@
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
<RepositoryType>digital data core abstractions clean architecture</RepositoryType>
<PackageTags>digital data core infrastructure clean architecture</PackageTags>
<Version>2.4.5</Version>
<AssemblyVersion>2.4.5</AssemblyVersion>
<FileVersion>2.4.5</FileVersion>
<Version>2.5.0</Version>
<AssemblyVersion>2.5.0</AssemblyVersion>
<FileVersion>2.5.0</FileVersion>
</PropertyGroup>
<ItemGroup>