Compare commits
3 Commits
5567f6731b
...
0cf6d2690a
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cf6d2690a | |||
| afbbac7b81 | |||
| d16a4b6bb4 |
@ -12,9 +12,9 @@
|
|||||||
<PackageIcon>core_icon.png</PackageIcon>
|
<PackageIcon>core_icon.png</PackageIcon>
|
||||||
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
||||||
<PackageTags>digital data core application clean architecture abstraction</PackageTags>
|
<PackageTags>digital data core application clean architecture abstraction</PackageTags>
|
||||||
<Version>1.4.0</Version>
|
<Version>1.5.0</Version>
|
||||||
<AssemblyVersion>1.4.0</AssemblyVersion>
|
<AssemblyVersion>1.5.0</AssemblyVersion>
|
||||||
<FileVersion>1.4.0</FileVersion>
|
<FileVersion>1.5.0</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using DigitalData.Core.Abstractions.Interfaces;
|
using System.Linq.Expressions;
|
||||||
using System.Linq.Expressions;
|
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -15,8 +14,8 @@ namespace DigitalData.Core.Abstraction.Application.Repository
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public interface IRepository<TEntity>
|
public interface IRepository<TEntity>
|
||||||
{
|
{
|
||||||
#region Create
|
#region Create
|
||||||
#if NET
|
#if NET
|
||||||
public
|
public
|
||||||
@ -71,6 +70,16 @@ public interface IRepository<TEntity>
|
|||||||
public
|
public
|
||||||
#endif
|
#endif
|
||||||
Task UpdateAsync<TDto>(TDto dto, Func<IQueryable<TEntity>, IQueryable<TEntity>> query, CancellationToken cancel = default);
|
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
|
#endregion Update
|
||||||
|
|
||||||
#region Delete
|
#region Delete
|
||||||
@ -98,7 +107,7 @@ public interface IRepository<TEntity>
|
|||||||
#endif
|
#endif
|
||||||
IQueryable<TEntity> ReadOnly();
|
IQueryable<TEntity> ReadOnly();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -21,8 +21,8 @@ namespace DigitalData.Core.Infrastructure
|
|||||||
{
|
{
|
||||||
#endif
|
#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 TDbContext Context;
|
||||||
|
|
||||||
protected internal readonly DbSet<TEntity> Entities;
|
protected internal readonly DbSet<TEntity> Entities;
|
||||||
@ -87,22 +87,25 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
|||||||
#region Update
|
#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 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);
|
var entities = await query(Entities).ToListAsync(cancel);
|
||||||
|
|
||||||
for (int i = entities.Count - 1; i >= 0; i--)
|
for (int i = entities.Count - 1; i >= 0; i--)
|
||||||
{
|
modification.Invoke(entities[i]);
|
||||||
Mapper
|
|
||||||
#if NET
|
|
||||||
!
|
|
||||||
#endif
|
|
||||||
.Map(dto, entities[i]);
|
|
||||||
Entities.Update(entities[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
await Context.SaveChangesAsync(cancel);
|
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
|
#endregion Update
|
||||||
|
|
||||||
#region Delete
|
#region Delete
|
||||||
@ -128,7 +131,7 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
|||||||
[Obsolete("Use IRepository<TEntity>.Get")]
|
[Obsolete("Use IRepository<TEntity>.Get")]
|
||||||
public virtual IQueryable<TEntity> ReadOnly() => Entities.AsNoTracking();
|
public virtual IQueryable<TEntity> ReadOnly() => Entities.AsNoTracking();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -13,9 +13,9 @@
|
|||||||
<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>
|
||||||
<Version>2.4.5</Version>
|
<Version>2.5.0</Version>
|
||||||
<AssemblyVersion>2.4.5</AssemblyVersion>
|
<AssemblyVersion>2.5.0</AssemblyVersion>
|
||||||
<FileVersion>2.4.5</FileVersion>
|
<FileVersion>2.5.0</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user