4 Commits

Author SHA1 Message Date
Developer 02
fb9449d701 chore: upradge versions 2025-04-22 23:05:04 +02:00
Developer 02
72f735272f feat(Repository): Add and implement ReadOrDefaultAsync method.
- add read method can map for each
2025-04-22 23:04:11 +02:00
Developer 02
304f5b7b4c chore: unnötiges Projektverzeichnis entfernt 2025-04-22 20:47:47 +02:00
Developer 02
0238310290 chore(Abstractions.Security): Hochgestuft auf 1.0.1 2025-04-22 20:46:09 +02:00
10 changed files with 59 additions and 19 deletions

View File

@@ -5,9 +5,9 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<PackageId>DigitalData.Core.Abstractions.Security</PackageId> <PackageId>DigitalData.Core.Abstractions.Security</PackageId>
<Version>1.0.0</Version> <Version>1.0.1</Version>
<AssemblyVersion>1.0.0</AssemblyVersion> <AssemblyVersion>1.0.1</AssemblyVersion>
<FileVersion>1.0.0</FileVersion> <FileVersion>1.0.1</FileVersion>
<Authors>Digital Data GmbH</Authors> <Authors>Digital Data GmbH</Authors>
<Company>Digital Data GmbH</Company> <Company>Digital Data GmbH</Company>
<Product>Digital Data GmbH</Product> <Product>Digital Data GmbH</Product>

View File

@@ -17,9 +17,9 @@
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl> <RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
<PackAsTool>False</PackAsTool> <PackAsTool>False</PackAsTool>
<PackageIcon>core_icon.png</PackageIcon> <PackageIcon>core_icon.png</PackageIcon>
<Version>3.4.1</Version> <Version>3.4.3</Version>
<AssemblyVersion>3.4.1</AssemblyVersion> <AssemblyVersion>3.4.3</AssemblyVersion>
<FileVersion>3.4.1</FileVersion> <FileVersion>3.4.3</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -20,15 +20,15 @@ public static class Extensions
#region Read #region Read
public static async Task<TEntity?> ReadFirstOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null) public static async Task<TEntity?> ReadFirstOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAsync(expression)).FirstOrDefault(); => (await repository.ReadAllAsync(expression)).FirstOrDefault();
public static async Task<TEntity> ReadFirstAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null) public static async Task<TEntity> ReadFirstAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAsync(expression)).First(); => (await repository.ReadAllAsync(expression)).First();
public static async Task<TEntity?> ReadSingleOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null) public static async Task<TEntity?> ReadSingleOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAsync(expression)).SingleOrDefault(); => (await repository.ReadAllAsync(expression)).SingleOrDefault();
public static async Task<TEntity> ReadSingleAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null) public static async Task<TEntity> ReadSingleAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAsync(expression)).Single(); => (await repository.ReadAllAsync(expression)).Single();
#endregion #endregion
} }

View File

@@ -14,6 +14,14 @@
/// <returns>The mapped DTO.</returns> /// <returns>The mapped DTO.</returns>
TDto Map<TDto>(TEntity entity); TDto Map<TDto>(TEntity entity);
/// <summary>
/// Maps an entity list to a DTO list.
/// </summary>
/// <typeparam name="TDto">The type of the DTO to map to.</typeparam>
/// <param name="entities">The entity list to be mapped.</param>
/// <returns>The mapped DTO list.</returns>
IEnumerable<TDto> Map<TDto>(IEnumerable<TEntity> entities);
/// <summary> /// <summary>
/// Maps a DTO to an entity. /// Maps a DTO to an entity.
/// </summary> /// </summary>
@@ -22,6 +30,14 @@
/// <returns>The mapped entity.</returns> /// <returns>The mapped entity.</returns>
TEntity Map<TDto>(TDto dto); TEntity Map<TDto>(TDto dto);
/// <summary>
/// Maps a DTO list to an entity list.
/// </summary>
/// <typeparam name="TDto">The type of the DTO to be mapped.</typeparam>
/// <param name="dtos">The DTO list to be mapped.</param>
/// <returns>The mapped entity list.</returns>
IEnumerable<TEntity> Map<TDto>(IEnumerable<TDto> dtos);
/// <summary> /// <summary>
/// Maps a DTO to an existing entity. /// Maps a DTO to an existing entity.
/// </summary> /// </summary>

View File

@@ -10,7 +10,13 @@ public interface IRepository<TEntity>
public Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken ct = default); public Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken ct = default);
public Task<IEnumerable<TEntity>> ReadAsync(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default); public Task<IEnumerable<TEntity>> ReadAllAsync(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default);
public Task<TEntity?> ReadOrDefaultAsync(Expression<Func<TEntity, bool>> expression, bool single = true, CancellationToken ct = default);
public Task<IEnumerable<TDto>> ReadAllAsync<TDto>(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default);
public Task<TDto?> ReadOrDefaultAsync<TDto>(Expression<Func<TEntity, bool>> expression, bool single = true, CancellationToken ct = default);
public Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default); public Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);

View File

@@ -6,7 +6,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>DigitalData.Core.Infrastructure.AutoMapper</PackageId> <PackageId>DigitalData.Core.Infrastructure.AutoMapper</PackageId>
<Version>1.0.0</Version> <Version>1.0.2</Version>
<Authors>Digital Data GmbH</Authors> <Authors>Digital Data GmbH</Authors>
<Company>Digital Data GmbH</Company> <Company>Digital Data GmbH</Company>
<Product>DigitalData.Core.Infrastructure.AutoMapper</Product> <Product>DigitalData.Core.Infrastructure.AutoMapper</Product>
@@ -16,8 +16,8 @@
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl> <RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
<RepositoryType>digital data core abstractions clean architecture mapping</RepositoryType> <RepositoryType>digital data core abstractions clean architecture mapping</RepositoryType>
<PackageTags>digital data core infrastructure clean architecture mapping</PackageTags> <PackageTags>digital data core infrastructure clean architecture mapping</PackageTags>
<AssemblyVersion>1.0.0</AssemblyVersion> <AssemblyVersion>1.0.2</AssemblyVersion>
<FileVersion>1.0.0</FileVersion> <FileVersion>1.0.2</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -14,7 +14,11 @@ public class EntityAutoMapper<TEntity> : IEntityMapper<TEntity>
public TDto Map<TDto>(TEntity entity) => _rootMapper.Map<TDto>(entity); public TDto Map<TDto>(TEntity entity) => _rootMapper.Map<TDto>(entity);
public IEnumerable<TDto> Map<TDto>(IEnumerable<TEntity> entities) => _rootMapper.Map<IEnumerable<TDto>>(entities);
public TEntity Map<TDto>(TDto dto) => _rootMapper.Map<TEntity>(dto); public TEntity Map<TDto>(TDto dto) => _rootMapper.Map<TEntity>(dto);
public IEnumerable<TEntity> Map<TDto>(IEnumerable<TDto> dtos) => _rootMapper.Map<IEnumerable<TEntity>>(dtos);
public TEntity Map<TDto>(TDto dto, TEntity entity) => _rootMapper.Map(dto, entity); public TEntity Map<TDto>(TDto dto, TEntity entity) => _rootMapper.Map(dto, entity);
} }

View File

@@ -33,11 +33,25 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
return entities; return entities;
} }
public virtual async Task<IEnumerable<TEntity>> ReadAsync(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default) public virtual async Task<IEnumerable<TEntity>> ReadAllAsync(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default)
=> expression is null => expression is null
? await Entities.AsNoTracking().ToListAsync(ct) ? await Entities.AsNoTracking().ToListAsync(ct)
: await Entities.AsNoTracking().Where(expression).ToListAsync(ct); : await Entities.AsNoTracking().Where(expression).ToListAsync(ct);
public virtual async Task<TEntity?> ReadOrDefaultAsync(Expression<Func<TEntity, bool>> expression, bool single = true, CancellationToken ct = default)
=> single
? await Entities.AsNoTracking().Where(expression).SingleOrDefaultAsync(ct)
: await Entities.AsNoTracking().Where(expression).FirstOrDefaultAsync(ct);
public virtual async Task<IEnumerable<TDto>> ReadAllAsync<TDto>(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default)
=> Mapper.Map<TDto>(await ReadAllAsync(expression, ct));
public virtual async Task<TDto?> ReadOrDefaultAsync<TDto>(Expression<Func<TEntity, bool>> expression, bool single = true, CancellationToken ct = default)
{
var entity = await ReadOrDefaultAsync(expression, single, ct);
return entity is null ? default : Mapper.Map<TDto>(entity);
}
public virtual async Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default) public virtual async Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default)
{ {
var entities = await Entities.Where(expression).ToListAsync(ct); var entities = await Entities.Where(expression).ToListAsync(ct);

View File

@@ -6,7 +6,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>DigitalData.Core.Infrastructure</PackageId> <PackageId>DigitalData.Core.Infrastructure</PackageId>
<Version>2.0.2</Version> <Version>2.0.4</Version>
<Authors>Digital Data GmbH</Authors> <Authors>Digital Data GmbH</Authors>
<Company>Digital Data GmbH</Company> <Company>Digital Data GmbH</Company>
<Product>DigitalData.Core.Infrastructure</Product> <Product>DigitalData.Core.Infrastructure</Product>
@@ -16,8 +16,8 @@
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl> <RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
<RepositoryType>digital data core abstractions clean architecture</RepositoryType> <RepositoryType>digital data core abstractions clean architecture</RepositoryType>
<PackageTags>digital data core infrastructure clean architecture</PackageTags> <PackageTags>digital data core infrastructure clean architecture</PackageTags>
<AssemblyVersion>2.0.2</AssemblyVersion> <AssemblyVersion>2.0.4</AssemblyVersion>
<FileVersion>2.0.2</FileVersion> <FileVersion>2.0.4</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -118,7 +118,7 @@ Global
{0FA93730-8084-4907-B172-87D610323796} = {EDF84A84-1E01-484E-B073-383F7139C891} {0FA93730-8084-4907-B172-87D610323796} = {EDF84A84-1E01-484E-B073-383F7139C891}
{9BC2DEC5-E89D-48CC-9A51-4D94496EE4A6} = {EDF84A84-1E01-484E-B073-383F7139C891} {9BC2DEC5-E89D-48CC-9A51-4D94496EE4A6} = {EDF84A84-1E01-484E-B073-383F7139C891}
{72CBAFBA-55CC-49C9-A484-F8F4550054CB} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} {72CBAFBA-55CC-49C9-A484-F8F4550054CB} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{C9266749-9504-4EA9-938F-F083357B60B7} = {00000000-0000-0000-0000-000000000000} {C9266749-9504-4EA9-938F-F083357B60B7} = {72CBAFBA-55CC-49C9-A484-F8F4550054CB}
{CE00E1F7-2771-4D9C-88FB-E564894E539E} = {41795B74-A757-4E93-B907-83BFF04EEE5C} {CE00E1F7-2771-4D9C-88FB-E564894E539E} = {41795B74-A757-4E93-B907-83BFF04EEE5C}
{41795B74-A757-4E93-B907-83BFF04EEE5C} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} {41795B74-A757-4E93-B907-83BFF04EEE5C} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection EndGlobalSection