From 7c70ceb7dced13b9986ca863098d46b52d81c59f Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Tue, 30 Jun 2020 12:18:28 +0430 Subject: [PATCH 01/22] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8a86642..298cc18 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # UnitOfWork +[![time tracker](https://wakatime.com/badge/github/AIKICo/UnitOfWork.svg)](https://wakatime.com/badge/github/AIKICo/UnitOfWork) A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported. ## Support MySQL multiple databases/tables sharding From 1e5008093297f710f079a7de593a5d292e48badb Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Tue, 30 Jun 2020 12:18:49 +0430 Subject: [PATCH 02/22] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 298cc18..45015fb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# UnitOfWork [![time tracker](https://wakatime.com/badge/github/AIKICo/UnitOfWork.svg)](https://wakatime.com/badge/github/AIKICo/UnitOfWork) +# UnitOfWork A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported. ## Support MySQL multiple databases/tables sharding From 483e0ae5489db0fb8d207d356dd1f0f4d0172aa0 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 4 Jul 2020 07:14:41 +0430 Subject: [PATCH 03/22] Upgrade Nuget packages --- samples/UnitOfWork.Host/Controllers/ValuesController.cs | 1 + samples/UnitOfWork.Host/Models/BlogggingContext.cs | 7 ++----- samples/UnitOfWork.Host/Models/CustomBlogRepository.cs | 4 +++- samples/UnitOfWork.Host/Startup.cs | 1 + samples/UnitOfWork.Host/UnitOfWork.Host.csproj | 1 + test/UnitOfWork.Tests/UnitOfWork.Tests.csproj | 1 + 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/samples/UnitOfWork.Host/Controllers/ValuesController.cs b/samples/UnitOfWork.Host/Controllers/ValuesController.cs index 5fcfe36..5ddff48 100644 --- a/samples/UnitOfWork.Host/Controllers/ValuesController.cs +++ b/samples/UnitOfWork.Host/Controllers/ValuesController.cs @@ -6,6 +6,7 @@ using Arch.EntityFrameworkCore.UnitOfWork.Host.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; +using UnitOfWork.Host.Models; namespace Arch.EntityFrameworkCore.UnitOfWork.Host.Controllers { diff --git a/samples/UnitOfWork.Host/Models/BlogggingContext.cs b/samples/UnitOfWork.Host/Models/BlogggingContext.cs index 1099928..caa208c 100644 --- a/samples/UnitOfWork.Host/Models/BlogggingContext.cs +++ b/samples/UnitOfWork.Host/Models/BlogggingContext.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore; -namespace Arch.EntityFrameworkCore.UnitOfWork.Host.Models +namespace UnitOfWork.Host.Models { public class BloggingContext : DbContext { @@ -12,10 +12,7 @@ public BloggingContext(DbContextOptions options) public DbSet Blogs { get; set; } public DbSet Posts { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.EnableAutoHistory(null); - } + protected override void OnModelCreating(ModelBuilder modelBuilder) => modelBuilder.EnableAutoHistory(null); } public class Blog diff --git a/samples/UnitOfWork.Host/Models/CustomBlogRepository.cs b/samples/UnitOfWork.Host/Models/CustomBlogRepository.cs index c706628..6b171e6 100644 --- a/samples/UnitOfWork.Host/Models/CustomBlogRepository.cs +++ b/samples/UnitOfWork.Host/Models/CustomBlogRepository.cs @@ -1,4 +1,6 @@ -namespace Arch.EntityFrameworkCore.UnitOfWork.Host.Models +using UnitOfWork.Host.Models; + +namespace Arch.EntityFrameworkCore.UnitOfWork.Host.Models { public class CustomBlogRepository : Repository, IRepository { diff --git a/samples/UnitOfWork.Host/Startup.cs b/samples/UnitOfWork.Host/Startup.cs index b706c5d..661ce9c 100644 --- a/samples/UnitOfWork.Host/Startup.cs +++ b/samples/UnitOfWork.Host/Startup.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Hosting; +using UnitOfWork.Host.Models; namespace Arch.EntityFrameworkCore.UnitOfWork.Host { diff --git a/samples/UnitOfWork.Host/UnitOfWork.Host.csproj b/samples/UnitOfWork.Host/UnitOfWork.Host.csproj index 3d001d5..31cc8c2 100644 --- a/samples/UnitOfWork.Host/UnitOfWork.Host.csproj +++ b/samples/UnitOfWork.Host/UnitOfWork.Host.csproj @@ -9,6 +9,7 @@ + diff --git a/test/UnitOfWork.Tests/UnitOfWork.Tests.csproj b/test/UnitOfWork.Tests/UnitOfWork.Tests.csproj index 1597ff6..d62790c 100644 --- a/test/UnitOfWork.Tests/UnitOfWork.Tests.csproj +++ b/test/UnitOfWork.Tests/UnitOfWork.Tests.csproj @@ -5,6 +5,7 @@ + From 8a607d8d175c1759e3ead371a3f9c9a469ff0309 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 11 Jul 2020 09:32:03 +0430 Subject: [PATCH 04/22] Add Ignore Query Filter For IsExists Method --- src/UnitOfWork/IRepository.cs | 3 +- src/UnitOfWork/Repository.cs | 120 ++++++++++++------------------- src/UnitOfWork/UnitOfWork.csproj | 2 + 3 files changed, 49 insertions(+), 76 deletions(-) diff --git a/src/UnitOfWork/IRepository.cs b/src/UnitOfWork/IRepository.cs index d69252a..33436ac 100644 --- a/src/UnitOfWork/IRepository.cs +++ b/src/UnitOfWork/IRepository.cs @@ -362,8 +362,9 @@ Task> GetAllAsync(Expression> predicate = nul /// Gets the Exists record based on a predicate. /// /// + /// /// - bool Exists(Expression> selector = null); + bool Exists(Expression> selector = null, bool ignoreQueryFilters = false); /// /// Gets the Async Exists record based on a predicate. /// diff --git a/src/UnitOfWork/Repository.cs b/src/UnitOfWork/Repository.cs index b358d3e..e149795 100644 --- a/src/UnitOfWork/Repository.cs +++ b/src/UnitOfWork/Repository.cs @@ -12,6 +12,7 @@ using Microsoft.EntityFrameworkCore.Query; using Arch.EntityFrameworkCore.UnitOfWork.Collections; using Microsoft.EntityFrameworkCore.ChangeTracking; +// ReSharper disable All namespace Arch.EntityFrameworkCore.UnitOfWork { @@ -53,10 +54,7 @@ public virtual void ChangeTable(string table) /// Gets all entities. This method is not recommended /// /// The . - public IQueryable GetAll() - { - return _dbSet; - } + public IQueryable GetAll() => _dbSet; /// /// Gets all entities. This method is not recommended @@ -607,12 +605,14 @@ public virtual async Task LongCountAsync(Expression> p /// /// /// /// decimal - public virtual T Max(Expression> predicate = null, Expression> selector = null) + public virtual T Max( + Expression> predicate = null, + Expression> selector = null) { if (predicate == null) - return _dbSet.Max(selector); + return _dbSet.Max(selector ?? throw new ArgumentNullException(nameof(selector))); else - return _dbSet.Where(predicate).Max(selector); + return _dbSet.Where(predicate).Max(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -624,9 +624,9 @@ public virtual T Max(Expression> predicate = null, Expres public virtual async Task MaxAsync(Expression> predicate = null, Expression> selector = null) { if (predicate == null) - return await _dbSet.MaxAsync(selector); + return await _dbSet.MaxAsync(selector ?? throw new ArgumentNullException(nameof(selector))); else - return await _dbSet.Where(predicate).MaxAsync(selector); + return await _dbSet.Where(predicate).MaxAsync(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -638,9 +638,9 @@ public virtual async Task MaxAsync(Expression> predica public virtual T Min(Expression> predicate = null, Expression> selector = null) { if (predicate == null) - return _dbSet.Min(selector); + return _dbSet.Min(selector ?? throw new ArgumentNullException(nameof(selector))); else - return _dbSet.Where(predicate).Min(selector); + return _dbSet.Where(predicate).Min(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -652,9 +652,9 @@ public virtual T Min(Expression> predicate = null, Expres public virtual async Task MinAsync(Expression> predicate = null, Expression> selector = null) { if (predicate == null) - return await _dbSet.MinAsync(selector); + return await _dbSet.MinAsync(selector ?? throw new ArgumentNullException(nameof(selector))); else - return await _dbSet.Where(predicate).MinAsync(selector); + return await _dbSet.Where(predicate).MinAsync(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -666,9 +666,9 @@ public virtual async Task MinAsync(Expression> predica public virtual decimal Average(Expression> predicate = null, Expression> selector = null) { if (predicate == null) - return _dbSet.Average(selector); + return _dbSet.Average(selector ?? throw new ArgumentNullException(nameof(selector))); else - return _dbSet.Where(predicate).Average(selector); + return _dbSet.Where(predicate).Average(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -680,9 +680,9 @@ public virtual decimal Average(Expression> predicate = null, public virtual async Task AverageAsync(Expression> predicate = null, Expression> selector = null) { if (predicate == null) - return await _dbSet.AverageAsync(selector); + return await _dbSet.AverageAsync(selector ?? throw new ArgumentNullException(nameof(selector))); else - return await _dbSet.Where(predicate).AverageAsync(selector); + return await _dbSet.Where(predicate).AverageAsync(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -691,12 +691,13 @@ public virtual async Task AverageAsync(Expression> /// /// /// /// decimal - public virtual decimal Sum(Expression> predicate = null, Expression> selector = null) + public virtual decimal Sum(Expression> predicate = null, + Expression> selector = null) { if (predicate == null) - return _dbSet.Sum(selector); + return _dbSet.Sum(selector ?? throw new ArgumentNullException(nameof(selector))); else - return _dbSet.Where(predicate).Sum(selector); + return _dbSet.Where(predicate).Sum(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -705,54 +706,40 @@ public virtual decimal Sum(Expression> predicate = null, Exp /// /// /// /// decimal - public virtual async Task SumAsync(Expression> predicate = null, Expression> selector = null) + public virtual async Task SumAsync( + Expression> predicate = null, + Expression> selector = null) { if (predicate == null) - return await _dbSet.SumAsync(selector); + return await _dbSet.SumAsync(selector ?? throw new ArgumentNullException(nameof(selector))); else - return await _dbSet.Where(predicate).SumAsync(selector); + return await _dbSet.Where(predicate).SumAsync(selector ?? throw new ArgumentNullException(nameof(selector))); } /// /// Gets the exists based on a predicate. /// /// + /// /// - public bool Exists(Expression> selector = null) + public bool Exists(Expression> selector = null, bool ignoreQueryFilters = false) { - if (selector == null) - { - return _dbSet.Any(); - } - else - { - return _dbSet.Any(selector); - } + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + return selector == null ? query.Any() : query.Any(selector); } /// /// Gets the async exists based on a predicate. /// /// /// - public async Task ExistsAsync(Expression> selector = null) - { - if (selector == null) - { - return await _dbSet.AnyAsync(); - } - else - { - return await _dbSet.AnyAsync(selector); - } - } + public async Task ExistsAsync(Expression> selector = null) => selector == null ? await _dbSet.AnyAsync() : await _dbSet.AnyAsync(selector); + /// /// Inserts a new entity synchronously. /// /// The entity to insert. - public virtual TEntity Insert(TEntity entity) - { - return _dbSet.Add(entity).Entity; - } + public virtual TEntity Insert(TEntity entity) => _dbSet.Add(entity).Entity; /// /// Inserts a range of entities synchronously. @@ -772,17 +759,13 @@ public virtual TEntity Insert(TEntity entity) /// The entity to insert. /// A to observe while waiting for the task to complete. /// A that represents the asynchronous insert operation. - public virtual ValueTask> InsertAsync(TEntity entity, CancellationToken cancellationToken = default(CancellationToken)) - { - return _dbSet.AddAsync(entity, cancellationToken); - - // Shadow properties? - //var property = _dbContext.Entry(entity).Property("Created"); - //if (property != null) { - //property.CurrentValue = DateTime.Now; - //} - } + public virtual ValueTask> InsertAsync(TEntity entity, CancellationToken cancellationToken = default(CancellationToken)) => _dbSet.AddAsync(entity, cancellationToken); + // Shadow properties? + //var property = _dbContext.Entry(entity).Property("Created"); + //if (property != null) { + //property.CurrentValue = DateTime.Now; + //} /// /// Inserts a range of entities asynchronously. /// @@ -802,20 +785,13 @@ public virtual TEntity Insert(TEntity entity) /// Updates the specified entity. /// /// The entity. - public virtual void Update(TEntity entity) - { - _dbSet.Update(entity); - } + public virtual void Update(TEntity entity) => _dbSet.Update(entity); /// /// Updates the specified entity. /// /// The entity. - public virtual void UpdateAsync(TEntity entity) - { - _dbSet.Update(entity); - - } + public virtual void UpdateAsync(TEntity entity) => _dbSet.Update(entity); /// /// Updates the specified entities. @@ -844,7 +820,7 @@ public virtual void Delete(object id) // using a stub entity to mark for deletion var typeInfo = typeof(TEntity).GetTypeInfo(); var key = _dbContext.Model.FindEntityType(typeInfo).FindPrimaryKey().Properties.FirstOrDefault(); - var property = typeInfo.GetProperty(key?.Name); + var property = typeInfo.GetProperty(key?.Name ?? string.Empty); if (property != null) { var entity = Activator.CreateInstance(); @@ -877,10 +853,7 @@ public virtual void Delete(object id) /// Gets all entities. This method is not recommended /// /// The . - public async Task> GetAllAsync() - { - return await _dbSet.ToListAsync(); - } + public async Task> GetAllAsync() => await _dbSet.ToListAsync(); /// /// Gets all entities. This method is not recommended @@ -934,9 +907,6 @@ public async Task> GetAllAsync(Expression> pr /// /// The entity. /// /// The entity state. - public void ChangeEntityState(TEntity entity, EntityState state) - { - _dbContext.Entry(entity).State = state; - } + public void ChangeEntityState(TEntity entity, EntityState state) => _dbContext.Entry(entity).State = state; } } diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index fdf335f..e25165e 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -17,6 +17,8 @@ 3.1.16 true snupkg + 8 + 3.1.17 From 61c713b39109d5433649f8acfc085bc775d2690d Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 11 Jul 2020 09:41:23 +0430 Subject: [PATCH 05/22] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 786029f..0f48815 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -30,4 +30,4 @@ jobs: - name: Pack nuget Package run: dotnet pack --configuration Release - name: push package to myget - run: dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_DEPLOY_KEY }} --source https://www.myget.org/F/my/api/v3/index.json + run: dotnet nuget push **/*.nupkg -s https://www.myget.org/F/my/api/v3/index.json -k ${{ secrets.NUGET_DEPLOY_KEY }} From 8d4ac2351d9bc4aadbefe8cf110c3bd8cd240975 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 11 Jul 2020 09:45:54 +0430 Subject: [PATCH 06/22] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 0f48815..99c183c 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -29,5 +29,5 @@ jobs: - uses: actions/checkout@v2 - name: Pack nuget Package run: dotnet pack --configuration Release - - name: push package to myget + - name: Push Package To Myget run: dotnet nuget push **/*.nupkg -s https://www.myget.org/F/my/api/v3/index.json -k ${{ secrets.NUGET_DEPLOY_KEY }} From e973d3963fe352d582ff2574a0bf7cee62293859 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 11 Jul 2020 09:48:54 +0430 Subject: [PATCH 07/22] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 99c183c..e476027 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -30,4 +30,4 @@ jobs: - name: Pack nuget Package run: dotnet pack --configuration Release - name: Push Package To Myget - run: dotnet nuget push **/*.nupkg -s https://www.myget.org/F/my/api/v3/index.json -k ${{ secrets.NUGET_DEPLOY_KEY }} + run: dotnet nuget push **/*.nupkg --skip-duplicate --no-symbols true -s https://www.myget.org/F/my/api/v3/index.json --api-key ${{ secrets.NUGET_DEPLOY_KEY }} From 3acb592dc6f23f8f4cd8647f689c0fbf93bcb562 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 11 Jul 2020 09:55:30 +0430 Subject: [PATCH 08/22] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index e476027..3e7ad91 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -30,4 +30,6 @@ jobs: - name: Pack nuget Package run: dotnet pack --configuration Release - name: Push Package To Myget - run: dotnet nuget push **/*.nupkg --skip-duplicate --no-symbols true -s https://www.myget.org/F/my/api/v3/index.json --api-key ${{ secrets.NUGET_DEPLOY_KEY }} + run: nuget push **/*.nupkg ${{ secrets.NUGET_DEPLOY_KEY }} -s https://www.myget.org/F/my/api/v3/index.json + # run: dotnet nuget push **/*.nupkg --skip-duplicate --no-symbols true -s https://www.myget.org/F/my/api/v3/index.json --api-key ${{ secrets.NUGET_DEPLOY_KEY }} + From a2bf8ecd072a421680ad0fb3e0a8a5e70a333551 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 11 Jul 2020 09:57:10 +0430 Subject: [PATCH 09/22] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 3e7ad91..ced4592 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -26,7 +26,10 @@ jobs: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: nuget/setup-nuget@v1 + with: + nuget-api-key: ${{ secrets.NUGET_DEPLOY_KEY }} + nuget-version: '5.x' - name: Pack nuget Package run: dotnet pack --configuration Release - name: Push Package To Myget From f510786564a97f9f455e471790821a61fcf2ec4a Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 11 Jul 2020 10:03:05 +0430 Subject: [PATCH 10/22] Update dotnetcore.yml --- .github/workflows/dotnetcore.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index ced4592..1ee4c44 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -26,13 +26,8 @@ jobs: needs: build runs-on: ubuntu-latest steps: - - uses: nuget/setup-nuget@v1 - with: - nuget-api-key: ${{ secrets.NUGET_DEPLOY_KEY }} - nuget-version: '5.x' - name: Pack nuget Package run: dotnet pack --configuration Release - name: Push Package To Myget - run: nuget push **/*.nupkg ${{ secrets.NUGET_DEPLOY_KEY }} -s https://www.myget.org/F/my/api/v3/index.json - # run: dotnet nuget push **/*.nupkg --skip-duplicate --no-symbols true -s https://www.myget.org/F/my/api/v3/index.json --api-key ${{ secrets.NUGET_DEPLOY_KEY }} + run: dotnet nuget push **/*.nupkg --skip-duplicate --no-symbols true -s https://www.myget.org/F/my/api/v3/index.json --api-key 0afee957-f20e-4af4-a998-625cb96b9de1 From 475aa724cd0ca0971a06119253fffb858e8e7ed7 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 11 Jul 2020 10:22:37 +0430 Subject: [PATCH 11/22] Add ignoreQueryFilters To ExistsAsync --- UnitOfWork.sln | 7 ------- samples/UnitOfWork.Host/UnitOfWork.Host.csproj | 1 + src/UnitOfWork/IRepository.cs | 3 ++- src/UnitOfWork/Repository.cs | 8 +++++++- src/UnitOfWork/UnitOfWork.csproj | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/UnitOfWork.sln b/UnitOfWork.sln index 15b7ef1..bc8872e 100644 --- a/UnitOfWork.sln +++ b/UnitOfWork.sln @@ -18,8 +18,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitOfWork", "src\UnitOfWor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitOfWork.Tests", "test\UnitOfWork.Tests\UnitOfWork.Tests.csproj", "{FDAA4086-21E8-4939-8539-0A1723EC4922}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitOfWork.Host", "samples\UnitOfWork.Host\UnitOfWork.Host.csproj", "{207188FE-2344-4DC1-8656-E02CEF741422}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,10 +32,6 @@ Global {FDAA4086-21E8-4939-8539-0A1723EC4922}.Debug|Any CPU.Build.0 = Debug|Any CPU {FDAA4086-21E8-4939-8539-0A1723EC4922}.Release|Any CPU.ActiveCfg = Release|Any CPU {FDAA4086-21E8-4939-8539-0A1723EC4922}.Release|Any CPU.Build.0 = Release|Any CPU - {207188FE-2344-4DC1-8656-E02CEF741422}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {207188FE-2344-4DC1-8656-E02CEF741422}.Debug|Any CPU.Build.0 = Debug|Any CPU - {207188FE-2344-4DC1-8656-E02CEF741422}.Release|Any CPU.ActiveCfg = Release|Any CPU - {207188FE-2344-4DC1-8656-E02CEF741422}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -45,7 +39,6 @@ Global GlobalSection(NestedProjects) = preSolution {FD8010C2-982B-470E-A9A5-C0DFA2D14809} = {14F86AF9-D2C9-468D-8C71-9BC4785F68A0} {FDAA4086-21E8-4939-8539-0A1723EC4922} = {D3C7F3F5-4AB2-4868-8D2C-516DFCFDC349} - {207188FE-2344-4DC1-8656-E02CEF741422} = {9661083F-4BCD-42D4-9EF8-1187DD9EDA60} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A7B21B30-8D65-449B-B192-64726743EFC3} diff --git a/samples/UnitOfWork.Host/UnitOfWork.Host.csproj b/samples/UnitOfWork.Host/UnitOfWork.Host.csproj index 31cc8c2..b2605a6 100644 --- a/samples/UnitOfWork.Host/UnitOfWork.Host.csproj +++ b/samples/UnitOfWork.Host/UnitOfWork.Host.csproj @@ -3,6 +3,7 @@ netcoreapp3.1 true Exe + false diff --git a/src/UnitOfWork/IRepository.cs b/src/UnitOfWork/IRepository.cs index 33436ac..e492cfe 100644 --- a/src/UnitOfWork/IRepository.cs +++ b/src/UnitOfWork/IRepository.cs @@ -369,8 +369,9 @@ Task> GetAllAsync(Expression> predicate = nul /// Gets the Async Exists record based on a predicate. /// /// + /// /// - Task ExistsAsync(Expression> selector = null); + Task ExistsAsync(Expression> selector = null, bool ignoreQueryFilters = false); /// /// Inserts a new entity synchronously. diff --git a/src/UnitOfWork/Repository.cs b/src/UnitOfWork/Repository.cs index e149795..2df279d 100644 --- a/src/UnitOfWork/Repository.cs +++ b/src/UnitOfWork/Repository.cs @@ -732,8 +732,14 @@ public bool Exists(Expression> selector = null, bool ignoreQ /// Gets the async exists based on a predicate. /// /// + /// /// - public async Task ExistsAsync(Expression> selector = null) => selector == null ? await _dbSet.AnyAsync() : await _dbSet.AnyAsync(selector); + public async Task ExistsAsync(Expression> selector = null, bool ignoreQueryFilters = false) + { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + return selector == null ? await query.AnyAsync() : await query.AnyAsync(selector); + } /// /// Inserts a new entity synchronously. diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index e25165e..5f5bcc8 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -18,7 +18,7 @@ true snupkg 8 - 3.1.17 + 3.1.18 From 8abcf80178a936399923ee98ec41d17f038f81d7 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 11 Jul 2020 10:24:13 +0430 Subject: [PATCH 12/22] Add ignoreQueryFilters To ExistsAsync --- src/UnitOfWork/UnitOfWork.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index 5f5bcc8..d901588 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -18,7 +18,7 @@ true snupkg 8 - 3.1.18 + 3.1.19 From 25891b8d5e77b0094a2ef63180c721627a8accf1 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sun, 12 Jul 2020 11:36:35 +0430 Subject: [PATCH 13/22] - --- .github/workflows/dotnetcore.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 1ee4c44..7ec8fd2 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -21,13 +21,4 @@ jobs: run: dotnet restore - name: Build run: dotnet build --configuration Release - - deploy: - needs: build - runs-on: ubuntu-latest - steps: - - name: Pack nuget Package - run: dotnet pack --configuration Release - - name: Push Package To Myget - run: dotnet nuget push **/*.nupkg --skip-duplicate --no-symbols true -s https://www.myget.org/F/my/api/v3/index.json --api-key 0afee957-f20e-4af4-a998-625cb96b9de1 - + From f0acb50a8ee3120f53702dc68c433b8925369931 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Fri, 16 Oct 2020 12:33:19 +0330 Subject: [PATCH 14/22] Upgrade NuGet packages --- src/UnitOfWork/UnitOfWork.csproj | 13 +++++++------ test/UnitOfWork.Tests/InMemoryContext.cs | 5 +---- test/UnitOfWork.Tests/UnitOfWork.Tests.csproj | 8 ++++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index d901588..4c18456 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -2,7 +2,7 @@ A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported. 3.1.0 - rigofunc;rigofunc@outlook.com; + rigofunc;rigofunc@outlook.com;qermezkon@gmail.com netstandard2.0 $(NoWarn);CS1591 true @@ -10,18 +10,19 @@ Microsoft.EntityFrameworkCore.UnitOfWork Microsoft.EntityFrameworkCore.UnitOfWork Entity Framework Core;entity-framework-core;EF;Data;O/RM;unitofwork;Unit Of Work;unit-of-work - https://github.com/arch/UnitOfWork + https://github.com/AikiCo/UnitOfWork MIT git - https://github.com/arch/UnitOfWork.git - 3.1.16 + https://github.com/AikiCo/UnitOfWork + 3.1.22 true snupkg 8 - 3.1.19 + 3.1.22 + true - + diff --git a/test/UnitOfWork.Tests/InMemoryContext.cs b/test/UnitOfWork.Tests/InMemoryContext.cs index cf60438..bf693dc 100644 --- a/test/UnitOfWork.Tests/InMemoryContext.cs +++ b/test/UnitOfWork.Tests/InMemoryContext.cs @@ -8,9 +8,6 @@ public class InMemoryContext : DbContext public DbSet Countries { get; set; } public DbSet Customers { get; set; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseInMemoryDatabase("test"); - } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseInMemoryDatabase("test"); } } diff --git a/test/UnitOfWork.Tests/UnitOfWork.Tests.csproj b/test/UnitOfWork.Tests/UnitOfWork.Tests.csproj index d62790c..e9dfcfa 100644 --- a/test/UnitOfWork.Tests/UnitOfWork.Tests.csproj +++ b/test/UnitOfWork.Tests/UnitOfWork.Tests.csproj @@ -5,11 +5,11 @@ - - - + + + - + all runtime; build; native; contentfiles; analyzers From fd3c7195c5caad054662e9fe2381eaeff978a59b Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Fri, 16 Oct 2020 12:34:38 +0330 Subject: [PATCH 15/22] - --- src/UnitOfWork/UnitOfWork.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index 4c18456..8505385 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -14,11 +14,11 @@ MIT git https://github.com/AikiCo/UnitOfWork - 3.1.22 + 3.1.23 true snupkg 8 - 3.1.22 + 3.1.23 true From 23375076494fa201560b2ac954bffc47f14d75fd Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 14 Nov 2020 08:12:39 +0330 Subject: [PATCH 16/22] Upgrade to dotnet 5.0 --- UnitOfWork.sln | 7 ------- src/UnitOfWork/UnitOfWork.csproj | 11 ++++++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/UnitOfWork.sln b/UnitOfWork.sln index bc8872e..9781ae6 100644 --- a/UnitOfWork.sln +++ b/UnitOfWork.sln @@ -16,8 +16,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{9661 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitOfWork", "src\UnitOfWork\UnitOfWork.csproj", "{FD8010C2-982B-470E-A9A5-C0DFA2D14809}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitOfWork.Tests", "test\UnitOfWork.Tests\UnitOfWork.Tests.csproj", "{FDAA4086-21E8-4939-8539-0A1723EC4922}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,17 +26,12 @@ Global {FD8010C2-982B-470E-A9A5-C0DFA2D14809}.Debug|Any CPU.Build.0 = Debug|Any CPU {FD8010C2-982B-470E-A9A5-C0DFA2D14809}.Release|Any CPU.ActiveCfg = Release|Any CPU {FD8010C2-982B-470E-A9A5-C0DFA2D14809}.Release|Any CPU.Build.0 = Release|Any CPU - {FDAA4086-21E8-4939-8539-0A1723EC4922}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FDAA4086-21E8-4939-8539-0A1723EC4922}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FDAA4086-21E8-4939-8539-0A1723EC4922}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FDAA4086-21E8-4939-8539-0A1723EC4922}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {FD8010C2-982B-470E-A9A5-C0DFA2D14809} = {14F86AF9-D2C9-468D-8C71-9BC4785F68A0} - {FDAA4086-21E8-4939-8539-0A1723EC4922} = {D3C7F3F5-4AB2-4868-8D2C-516DFCFDC349} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A7B21B30-8D65-449B-B192-64726743EFC3} diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index 8505385..4231d87 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -3,7 +3,7 @@ A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported. 3.1.0 rigofunc;rigofunc@outlook.com;qermezkon@gmail.com - netstandard2.0 + netstandard2.1 $(NoWarn);CS1591 true true @@ -14,15 +14,16 @@ MIT git https://github.com/AikiCo/UnitOfWork - 3.1.23 + 3.1.24 true snupkg 8 - 3.1.23 + 3.1.24 true + cba3a20d-f192-445e-9058-fdbacec3fea3 - - + + From d814777ab6d3c45a7a2c386371c2b03b6595a719 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 14 Nov 2020 08:17:16 +0330 Subject: [PATCH 17/22] - --- src/UnitOfWork/UnitOfWork.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index 4231d87..42e6fdd 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -14,11 +14,11 @@ MIT git https://github.com/AikiCo/UnitOfWork - 3.1.24 + 5.0.0 true snupkg 8 - 3.1.24 + 5.0.0 true cba3a20d-f192-445e-9058-fdbacec3fea3 From c654275d5c4a5f97bcb089e5194a75899cbd2285 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 12 Jun 2021 10:24:13 +0430 Subject: [PATCH 18/22] - --- src/UnitOfWork/IRepository.cs | 46 +++++++----- src/UnitOfWork/Repository.cs | 120 +++++++++++++++++++++---------- src/UnitOfWork/UnitOfWork.csproj | 10 +-- 3 files changed, 118 insertions(+), 58 deletions(-) diff --git a/src/UnitOfWork/IRepository.cs b/src/UnitOfWork/IRepository.cs index e492cfe..bc6ac94 100644 --- a/src/UnitOfWork/IRepository.cs +++ b/src/UnitOfWork/IRepository.cs @@ -270,93 +270,105 @@ Task> GetAllAsync(Expression> predicate = nul /// Gets the count based on a predicate. /// /// + /// /// - int Count(Expression> predicate = null); + int Count(Expression> predicate = null, bool ignoreQueryFilters = false); /// /// Gets async the count based on a predicate. /// /// + /// /// - Task CountAsync(Expression> predicate = null); + Task CountAsync(Expression> predicate = null, bool ignoreQueryFilters = false); /// /// Gets the long count based on a predicate. /// /// + /// /// - long LongCount(Expression> predicate = null); + long LongCount(Expression> predicate = null, bool ignoreQueryFilters = false); /// /// Gets async the long count based on a predicate. /// /// + /// /// - Task LongCountAsync(Expression> predicate = null); + Task LongCountAsync(Expression> predicate = null, bool ignoreQueryFilters = false); /// /// Gets the max based on a predicate. /// /// /// /// + /// /// decimal - T Max(Expression> predicate = null, Expression> selector = null); + T Max(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false); /// /// Gets the async max based on a predicate. /// /// /// /// + /// /// decimal - Task MaxAsync(Expression> predicate = null, Expression> selector = null); + Task MaxAsync(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false); /// /// Gets the min based on a predicate. /// /// /// + /// /// decimal - T Min(Expression> predicate = null, Expression> selector = null); + T Min(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false); /// /// Gets the async min based on a predicate. /// /// /// + /// /// decimal - Task MinAsync(Expression> predicate = null, Expression> selector = null); + Task MinAsync(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false); /// /// Gets the average based on a predicate. /// /// /// /// + /// /// decimal - decimal Average (Expression> predicate = null, Expression> selector = null); + decimal Average (Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false); /// - /// Gets the async average based on a predicate. - /// - /// - /// /// - /// decimal - Task AverageAsync(Expression> predicate = null, Expression> selector = null); + /// Gets the async average based on a predicate. + /// + /// + /// /// + /// + /// decimal + Task AverageAsync(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false); /// /// Gets the sum based on a predicate. /// /// /// /// + /// /// decimal - decimal Sum (Expression> predicate = null, Expression> selector = null); + decimal Sum (Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false); /// /// Gets the async sum based on a predicate. /// /// /// /// + /// /// decimal - Task SumAsync (Expression> predicate = null, Expression> selector = null); + Task SumAsync (Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false); /// /// Gets the Exists record based on a predicate. diff --git a/src/UnitOfWork/Repository.cs b/src/UnitOfWork/Repository.cs index 2df279d..f4bcdbf 100644 --- a/src/UnitOfWork/Repository.cs +++ b/src/UnitOfWork/Repository.cs @@ -535,16 +535,20 @@ public virtual async Task GetFirstOrDefaultAsync(Expression /// + /// /// - public virtual int Count(Expression> predicate = null) + public virtual int Count(Expression> predicate = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) { - return _dbSet.Count(); + return query.Count(); } else { - return _dbSet.Count(predicate); + return query.Count(predicate); } } @@ -552,16 +556,20 @@ public virtual int Count(Expression> predicate = null) /// Gets async the count based on a predicate. /// /// + /// /// - public virtual async Task CountAsync(Expression> predicate = null) + public virtual async Task CountAsync(Expression> predicate = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) { - return await _dbSet.CountAsync(); + return await query.CountAsync(); } else { - return await _dbSet.CountAsync(predicate); + return await query.CountAsync(predicate); } } @@ -569,16 +577,20 @@ public virtual async Task CountAsync(Expression> predic /// Gets the long count based on a predicate. /// /// + /// /// - public virtual long LongCount(Expression> predicate = null) + public virtual long LongCount(Expression> predicate = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) { - return _dbSet.LongCount(); + return query.LongCount(); } else { - return _dbSet.LongCount(predicate); + return query.LongCount(predicate); } } @@ -586,16 +598,20 @@ public virtual long LongCount(Expression> predicate = null) /// Gets async the long count based on a predicate. /// /// + /// /// - public virtual async Task LongCountAsync(Expression> predicate = null) + public virtual async Task LongCountAsync(Expression> predicate = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) { - return await _dbSet.LongCountAsync(); + return await query.LongCountAsync(); } else { - return await _dbSet.LongCountAsync(predicate); + return await query.LongCountAsync(predicate); } } @@ -604,15 +620,19 @@ public virtual async Task LongCountAsync(Expression> p /// /// /// /// + /// /// decimal public virtual T Max( Expression> predicate = null, - Expression> selector = null) + Expression> selector = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) - return _dbSet.Max(selector ?? throw new ArgumentNullException(nameof(selector))); + return query.Max(selector ?? throw new ArgumentNullException(nameof(selector))); else - return _dbSet.Where(predicate).Max(selector ?? throw new ArgumentNullException(nameof(selector))); + return query.Where(predicate).Max(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -620,13 +640,17 @@ public virtual T Max( /// /// /// /// + /// /// decimal - public virtual async Task MaxAsync(Expression> predicate = null, Expression> selector = null) + public virtual async Task MaxAsync(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) - return await _dbSet.MaxAsync(selector ?? throw new ArgumentNullException(nameof(selector))); + return await query.MaxAsync(selector ?? throw new ArgumentNullException(nameof(selector))); else - return await _dbSet.Where(predicate).MaxAsync(selector ?? throw new ArgumentNullException(nameof(selector))); + return await query.Where(predicate).MaxAsync(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -634,13 +658,17 @@ public virtual async Task MaxAsync(Expression> predica /// /// /// /// + /// /// decimal - public virtual T Min(Expression> predicate = null, Expression> selector = null) + public virtual T Min(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) - return _dbSet.Min(selector ?? throw new ArgumentNullException(nameof(selector))); + return query.Min(selector ?? throw new ArgumentNullException(nameof(selector))); else - return _dbSet.Where(predicate).Min(selector ?? throw new ArgumentNullException(nameof(selector))); + return query.Where(predicate).Min(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -648,13 +676,17 @@ public virtual T Min(Expression> predicate = null, Expres /// /// /// /// + /// /// decimal - public virtual async Task MinAsync(Expression> predicate = null, Expression> selector = null) + public virtual async Task MinAsync(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) - return await _dbSet.MinAsync(selector ?? throw new ArgumentNullException(nameof(selector))); + return await query.MinAsync(selector ?? throw new ArgumentNullException(nameof(selector))); else - return await _dbSet.Where(predicate).MinAsync(selector ?? throw new ArgumentNullException(nameof(selector))); + return await query.Where(predicate).MinAsync(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -662,13 +694,17 @@ public virtual async Task MinAsync(Expression> predica /// /// /// /// + /// /// decimal - public virtual decimal Average(Expression> predicate = null, Expression> selector = null) + public virtual decimal Average(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) - return _dbSet.Average(selector ?? throw new ArgumentNullException(nameof(selector))); + return query.Average(selector ?? throw new ArgumentNullException(nameof(selector))); else - return _dbSet.Where(predicate).Average(selector ?? throw new ArgumentNullException(nameof(selector))); + return query.Where(predicate).Average(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -676,13 +712,17 @@ public virtual decimal Average(Expression> predicate = null, /// /// /// /// + /// /// decimal - public virtual async Task AverageAsync(Expression> predicate = null, Expression> selector = null) + public virtual async Task AverageAsync(Expression> predicate = null, Expression> selector = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) - return await _dbSet.AverageAsync(selector ?? throw new ArgumentNullException(nameof(selector))); + return await query.AverageAsync(selector ?? throw new ArgumentNullException(nameof(selector))); else - return await _dbSet.Where(predicate).AverageAsync(selector ?? throw new ArgumentNullException(nameof(selector))); + return await query.Where(predicate).AverageAsync(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -690,14 +730,18 @@ public virtual async Task AverageAsync(Expression> /// /// /// /// + /// /// decimal public virtual decimal Sum(Expression> predicate = null, - Expression> selector = null) + Expression> selector = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) - return _dbSet.Sum(selector ?? throw new ArgumentNullException(nameof(selector))); + return query.Sum(selector ?? throw new ArgumentNullException(nameof(selector))); else - return _dbSet.Where(predicate).Sum(selector ?? throw new ArgumentNullException(nameof(selector))); + return query.Where(predicate).Sum(selector ?? throw new ArgumentNullException(nameof(selector))); } /// @@ -705,15 +749,19 @@ public virtual decimal Sum(Expression> predicate = null, /// /// /// /// + /// /// decimal public virtual async Task SumAsync( Expression> predicate = null, - Expression> selector = null) + Expression> selector = null, bool ignoreQueryFilters = false) { + IQueryable query = _dbSet; + if (ignoreQueryFilters) query = query.IgnoreQueryFilters(); + if (predicate == null) - return await _dbSet.SumAsync(selector ?? throw new ArgumentNullException(nameof(selector))); + return await query.SumAsync(selector ?? throw new ArgumentNullException(nameof(selector))); else - return await _dbSet.Where(predicate).SumAsync(selector ?? throw new ArgumentNullException(nameof(selector))); + return await query.Where(predicate).SumAsync(selector ?? throw new ArgumentNullException(nameof(selector))); } /// diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index 42e6fdd..0d18d79 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -1,7 +1,7 @@  A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported. - 3.1.0 + 5.0.7 rigofunc;rigofunc@outlook.com;qermezkon@gmail.com netstandard2.1 $(NoWarn);CS1591 @@ -14,16 +14,16 @@ MIT git https://github.com/AikiCo/UnitOfWork - 5.0.0 + 5.0.7 true snupkg 8 - 5.0.0 + 5.0.7 true cba3a20d-f192-445e-9058-fdbacec3fea3 - - + + From 9f4e970c1dbcddafe96a59d8e5e9d5c8305c7646 Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Sat, 12 Jun 2021 10:33:36 +0430 Subject: [PATCH 19/22] - --- src/UnitOfWork/IRepository.cs | 34 ++++++++++++ src/UnitOfWork/Repository.cs | 99 +++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/src/UnitOfWork/IRepository.cs b/src/UnitOfWork/IRepository.cs index bc6ac94..9f96f06 100644 --- a/src/UnitOfWork/IRepository.cs +++ b/src/UnitOfWork/IRepository.cs @@ -52,6 +52,40 @@ IPagedList GetPagedList(Expression> predicate = nul bool disableTracking = true, bool ignoreQueryFilters = false); + /// + /// Gets all entities. This method is not recommended + /// + /// The selector for projection. + /// A function to test each element for a condition. + /// A function to order elements. + /// A function to include navigation properties + /// true to disable changing tracking; otherwise, false. Default to true. + /// Ignore query filters + /// An that contains elements that satisfy the condition specified by . + /// Ex: This method defaults to a read-only, no-tracking query. + IQueryable GetAll(Expression> selector, + Expression> predicate = null, + Func, IOrderedQueryable> orderBy = null, + Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false); + + /// + /// Gets all entities. This method is not recommended + /// + /// The selector for projection. + /// A function to test each element for a condition. + /// A function to order elements. + /// A function to include navigation properties + /// true to disable changing tracking; otherwise, false. Default to true. + /// Ignore query filters + /// An that contains elements that satisfy the condition specified by . + /// Ex: This method defaults to a read-only, no-tracking query. + Task> GetAllAsync(Expression> selector, + Expression> predicate = null, + Func, IOrderedQueryable> orderBy = null, + Func, IIncludableQueryable> include = null, + bool disableTracking = true, + bool ignoreQueryFilters = false); + /// /// Gets the based on a predicate, orderby delegate and page information. This method default no-tracking query. /// diff --git a/src/UnitOfWork/Repository.cs b/src/UnitOfWork/Repository.cs index f4bcdbf..1dbdecf 100644 --- a/src/UnitOfWork/Repository.cs +++ b/src/UnitOfWork/Repository.cs @@ -102,6 +102,105 @@ public IQueryable GetAll( return query; } } + + /// + /// Gets all entities. This method is not recommended + /// + /// The selector for projection. + /// A function to test each element for a condition. + /// A function to order elements. + /// A function to include navigation properties + /// true to disable changing tracking; otherwise, false. Default to true. + /// Ignore query filters + /// An that contains elements that satisfy the condition specified by . + /// Ex: This method defaults to a read-only, no-tracking query. + public IQueryable GetAll(Expression> selector, + Expression> predicate = null, + Func, IOrderedQueryable> orderBy = null, + Func, IIncludableQueryable> include = null, bool disableTracking = true, bool ignoreQueryFilters = false) + { + IQueryable query = _dbSet; + + if (disableTracking) + { + query = query.AsNoTracking(); + } + + if (include != null) + { + query = include(query); + } + + if (predicate != null) + { + query = query.Where(predicate); + } + + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + + if (orderBy != null) + { + return orderBy(query).Select(selector); + } + else + { + return query.Select(selector); + } + } + + /// + /// Gets all entities. This method is not recommended + /// + /// The selector for projection. + /// A function to test each element for a condition. + /// A function to order elements. + /// A function to include navigation properties + /// true to disable changing tracking; otherwise, false. Default to true. + /// Ignore query filters + /// An that contains elements that satisfy the condition specified by . + /// Ex: This method defaults to a read-only, no-tracking query. + public async Task> GetAllAsync(Expression> selector, + Expression> predicate = null, + Func, IOrderedQueryable> orderBy = null, + Func, IIncludableQueryable> include = null, + bool disableTracking = true, bool ignoreQueryFilters = false) + { + IQueryable query = _dbSet; + + if (disableTracking) + { + query = query.AsNoTracking(); + } + + if (include != null) + { + query = include(query); + } + + if (predicate != null) + { + query = query.Where(predicate); + } + + if (ignoreQueryFilters) + { + query = query.IgnoreQueryFilters(); + } + + + if (orderBy != null) + { + return await orderBy(query).Select(selector).ToListAsync(); + } + else + { + return await query.Select(selector).ToListAsync(); + } + } + /// /// Gets the based on a predicate, orderby delegate and page information. This method default no-tracking query. /// From 3321f504a3f4adf9a0fb649dcb0720c9c7cf1d3c Mon Sep 17 00:00:00 2001 From: Mohammad Mehrnia Date: Fri, 10 Dec 2021 03:59:13 +0330 Subject: [PATCH 20/22] - --- src/UnitOfWork/IRepository.cs | 36 -------------------------------- src/UnitOfWork/UnitOfWork.csproj | 6 +++--- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/src/UnitOfWork/IRepository.cs b/src/UnitOfWork/IRepository.cs index 1b0468f..9f96f06 100644 --- a/src/UnitOfWork/IRepository.cs +++ b/src/UnitOfWork/IRepository.cs @@ -278,24 +278,6 @@ IQueryable GetAll(Expression> predicate = null, bool disableTracking = true, bool ignoreQueryFilters = false); - /// - /// Gets all entities. This method is not recommended - /// - /// The selector for projection. - /// A function to test each element for a condition. - /// A function to order elements. - /// A function to include navigation properties - /// true to disable changing tracking; otherwise, false. Default to true. - /// Ignore query filters - /// An that contains elements that satisfy the condition specified by . - /// Ex: This method defaults to a read-only, no-tracking query. - IQueryable GetAll(Expression> selector, - Expression> predicate = null, - Func, IOrderedQueryable> orderBy = null, - Func, IIncludableQueryable> include = null, - bool disableTracking = true, - bool ignoreQueryFilters = false); - /// /// Gets all entities. This method is not recommended /// @@ -318,24 +300,6 @@ Task> GetAllAsync(Expression> predicate = nul bool disableTracking = true, bool ignoreQueryFilters = false); - /// - /// Gets all entities. This method is not recommended - /// - /// The selector for projection. - /// A function to test each element for a condition. - /// A function to order elements. - /// A function to include navigation properties - /// true to disable changing tracking; otherwise, false. Default to true. - /// Ignore query filters - /// An that contains elements that satisfy the condition specified by . - /// Ex: This method defaults to a read-only, no-tracking query. - Task> GetAllAsync(Expression> selector, - Expression> predicate = null, - Func, IOrderedQueryable> orderBy = null, - Func, IIncludableQueryable> include = null, - bool disableTracking = true, - bool ignoreQueryFilters = false); - /// /// Gets the count based on a predicate. /// diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index 0d18d79..82fe76b 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -3,7 +3,7 @@ A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported. 5.0.7 rigofunc;rigofunc@outlook.com;qermezkon@gmail.com - netstandard2.1 + net6.0 $(NoWarn);CS1591 true true @@ -14,11 +14,11 @@ MIT git https://github.com/AikiCo/UnitOfWork - 5.0.7 + 6.0.0 true snupkg 8 - 5.0.7 + 6.0.0 true cba3a20d-f192-445e-9058-fdbacec3fea3 From 75f8500f9a4cabae879577896bf1bd21ebac9b82 Mon Sep 17 00:00:00 2001 From: Mohammad Date: Sun, 13 Nov 2022 07:25:39 +0330 Subject: [PATCH 21/22] - --- .cr/personal/FavoritesList/List.xml | 6 ++++++ src/UnitOfWork/UnitOfWork.csproj | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .cr/personal/FavoritesList/List.xml diff --git a/.cr/personal/FavoritesList/List.xml b/.cr/personal/FavoritesList/List.xml new file mode 100644 index 0000000..a60e5ed --- /dev/null +++ b/.cr/personal/FavoritesList/List.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index 82fe76b..c1ed1e2 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -1,9 +1,9 @@  A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported. - 5.0.7 + 7.0.0 rigofunc;rigofunc@outlook.com;qermezkon@gmail.com - net6.0 + net7.0 $(NoWarn);CS1591 true true @@ -14,16 +14,16 @@ MIT git https://github.com/AikiCo/UnitOfWork - 6.0.0 + 7.0.0 true snupkg 8 - 6.0.0 + 7.0.0 true cba3a20d-f192-445e-9058-fdbacec3fea3 - - + + From 7377e0aae50bee160f339b62cf3eabfb21b74391 Mon Sep 17 00:00:00 2001 From: Mohammad Date: Sun, 8 Jan 2023 10:35:59 +0330 Subject: [PATCH 22/22] * Add Bulk update * Add Bulk Delete --- src/UnitOfWork/IRepository.cs | 22 ++++++++++++++++++++++ src/UnitOfWork/Repository.cs | 23 +++++++++++++++++++++++ src/UnitOfWork/UnitOfWork.csproj | 6 +++--- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/UnitOfWork/IRepository.cs b/src/UnitOfWork/IRepository.cs index 9f96f06..fe93c07 100644 --- a/src/UnitOfWork/IRepository.cs +++ b/src/UnitOfWork/IRepository.cs @@ -502,6 +502,28 @@ Task> GetAllAsync(Expression> predicate = nul /// The entities. void Delete(IEnumerable entities); + /// + /// Bulk Delete the specified entity. + /// + void BulkDelete(); + + /// + /// ASync Bulk Delete the specified entity. + /// + Task BulkDeleteAsync(); + + /// + /// Bulk Update the specified entity. + /// the entity property + /// + void BulkUpdate(Expression, SetPropertyCalls>> setPropertyCalls); + + /// + /// Async Bulk Update the specified entity. + /// the entity property + /// + Task BulkUpdateAsync(Expression, SetPropertyCalls>> setPropertyCalls); + /// /// Change entity state for patch method on web api. /// diff --git a/src/UnitOfWork/Repository.cs b/src/UnitOfWork/Repository.cs index 1dbdecf..005946c 100644 --- a/src/UnitOfWork/Repository.cs +++ b/src/UnitOfWork/Repository.cs @@ -1055,6 +1055,29 @@ public async Task> GetAllAsync(Expression> pr } } + /// + /// Bulk Delete the specified entity. + /// + public void BulkDelete()=> _dbSet.ExecuteDelete(); + + /// + /// Bulk Delete the specified entity. + /// + public async Task BulkDeleteAsync() => await _dbSet.ExecuteDeleteAsync(); + + + /// + /// Bulk Update the specified entity. + /// + /// the entity property + public void BulkUpdate(Expression, SetPropertyCalls>> setPropertyCalls) => _dbSet.ExecuteUpdate(setPropertyCalls); + + /// + /// Async Bulk Update the specified entity. + /// the entity property + /// + public async Task BulkUpdateAsync(Expression, SetPropertyCalls>> setPropertyCalls) => await _dbSet.ExecuteUpdateAsync(setPropertyCalls); + /// /// Change entity state for patch method on web api. /// diff --git a/src/UnitOfWork/UnitOfWork.csproj b/src/UnitOfWork/UnitOfWork.csproj index c1ed1e2..1494a93 100644 --- a/src/UnitOfWork/UnitOfWork.csproj +++ b/src/UnitOfWork/UnitOfWork.csproj @@ -1,7 +1,7 @@  A plugin for Microsoft.EntityFrameworkCore to support repository, unit of work patterns, and multiple database with distributed transaction supported. - 7.0.0 + 7.1.0 rigofunc;rigofunc@outlook.com;qermezkon@gmail.com net7.0 $(NoWarn);CS1591 @@ -14,11 +14,11 @@ MIT git https://github.com/AikiCo/UnitOfWork - 7.0.0 + 7.1.0 true snupkg 8 - 7.0.0 + 7.1.0 true cba3a20d-f192-445e-9058-fdbacec3fea3