diff --git a/src/core/Dime.Repositories.Sql/Dime.Repositories.Sql.csproj b/src/core/Dime.Repositories.Sql/Dime.Repositories.Sql.csproj index 90ad03f..13f5ebb 100644 --- a/src/core/Dime.Repositories.Sql/Dime.Repositories.Sql.csproj +++ b/src/core/Dime.Repositories.Sql/Dime.Repositories.Sql.csproj @@ -1,11 +1,11 @@  - 2.0.2.0 - 2.0.2.0 - 2.0.2.0 + 2.0.3.0 + 2.0.3.0 + 2.0.3.0 Dime Software - 2.0.2.0 + 2.0.3.0 Dime Software net8.0 Dime.Repositories.Sql diff --git a/src/core/Dime.Repositories.Sql/ISqlRepository.cs b/src/core/Dime.Repositories.Sql/ISqlRepository.cs index 2383bff..785a43f 100644 --- a/src/core/Dime.Repositories.Sql/ISqlRepository.cs +++ b/src/core/Dime.Repositories.Sql/ISqlRepository.cs @@ -5,60 +5,62 @@ namespace Dime.Repositories { /// - /// + /// Defines a SQL repository interface with support for executing SQL commands and stored procedures. /// - /// + /// The type of the entity. public interface ISqlRepository : IRepository, IStoredProcedureRepository where T : class { /// - /// Executes the SQL asynchronous. + /// Executes the provided SQL command asynchronously. /// - /// The SQL. - /// + /// The SQL command to execute. + /// A task that represents the asynchronous operation. Task ExecuteSqlAsync(string sql); /// - /// Executes the stored procedure asynchronous. + /// Executes the specified stored procedure asynchronously. /// - /// The name of the stored procedure. - /// The parameters. - /// + /// The name of the stored procedure to execute. + /// The parameters to pass to the stored procedure. + /// A task that represents the asynchronous operation. The task result contains the number of rows affected. Task ExecuteStoredProcedureAsync(string command, params DbParameter[] parameters); /// - /// Executes the stored procedure asynchronous. + /// Executes the specified stored procedure asynchronously with a given schema. /// - /// The name of the stored procedure. - /// - /// The parameters. - /// + /// The name of the stored procedure to execute. + /// The schema of the stored procedure. Defaults to "dbo". + /// The parameters to pass to the stored procedure. + /// A task that represents the asynchronous operation. The task result contains the number of rows affected. Task ExecuteStoredProcedureAsync(string command, string schema = "dbo", params DbParameter[] parameters); /// - /// Executes the stored procedure asynchronous. + /// Executes the specified stored procedure asynchronously and returns a single result. /// - /// The name of the stored procedure. - /// - /// The parameters. - /// + /// The type of the result. + /// The name of the stored procedure to execute. + /// The schema of the stored procedure. Defaults to "dbo". + /// The parameters to pass to the stored procedure. + /// A task that represents the asynchronous operation. The task result contains the result of the stored procedure. Task ExecuteStoredProcedureAsync(TResult command, string schema = "dbo", params DbParameter[] parameters); /// - /// Executes the stored procedure asynchronous. + /// Executes the specified stored procedure asynchronously and returns a collection of results. /// - /// The name of the stored procedure. - /// The parameters. - /// + /// The type of the results. + /// The name of the stored procedure to execute. + /// The parameters to pass to the stored procedure. + /// A task that represents the asynchronous operation. The task result contains a collection of results. Task> ExecuteStoredProcedureAsync(string command, params DbParameter[] parameters); /// - /// + /// Executes the specified stored procedure asynchronously with a given schema and returns a collection of results. /// - /// - /// - /// - /// - /// + /// The type of the results. + /// The name of the stored procedure to execute. + /// The schema of the stored procedure. Defaults to "dbo". + /// The parameters to pass to the stored procedure. + /// A task that represents the asynchronous operation. The task result contains a collection of results. Task> ExecuteStoredProcedureAsync(string name, string schema = "dbo", params DbParameter[] parameters); } } \ No newline at end of file diff --git a/src/core/Dime.Repositories/Dime.Repositories.csproj b/src/core/Dime.Repositories/Dime.Repositories.csproj index e38b3e5..501e91b 100644 --- a/src/core/Dime.Repositories/Dime.Repositories.csproj +++ b/src/core/Dime.Repositories/Dime.Repositories.csproj @@ -1,10 +1,10 @@  - 2.0.0.0 - 2.0.0.0 - 2.0.0.0 + 2.0.1.0 + 2.0.1.0 + 2.0.1.0 Dime Software - 2.0.0.0 + 2.0.1.0 net8.0 Dime.Repositories Dime.Repositories diff --git a/src/core/Dime.Repositories/Interfaces/Repository/IDeleteRepository.cs b/src/core/Dime.Repositories/Interfaces/Repository/IDeleteRepository.cs index 42ad35c..bb1c570 100644 --- a/src/core/Dime.Repositories/Interfaces/Repository/IDeleteRepository.cs +++ b/src/core/Dime.Repositories/Interfaces/Repository/IDeleteRepository.cs @@ -25,6 +25,12 @@ public interface IDeleteRepository : IDisposable where TEntity : class /// Void Task DeleteAsync(object? id); + /// + /// Removes all records + /// + /// Task + Task DeleteAsync(); + /// /// Removes the record from the data store by its identifier /// diff --git a/src/core/Dime.Repositories/Models/Page.cs b/src/core/Dime.Repositories/Models/Page.cs index d8c75d4..6d9f291 100644 --- a/src/core/Dime.Repositories/Models/Page.cs +++ b/src/core/Dime.Repositories/Models/Page.cs @@ -14,7 +14,7 @@ public Page() public Page(IEnumerable data) { Data = data; - Summary = new List(); + Summary = []; } public Page(IEnumerable data, int total) @@ -32,7 +32,7 @@ public Page(IEnumerable data, int total, string message) public Page(IEnumerable data, int total, string message, IEnumerable summary) : this(data, total, message) { - Summary = summary != null ? summary.ToList() : new List(); + Summary = summary != null ? summary.ToList() : []; } public IEnumerable Data { get; set; } diff --git a/src/providers/EntityFramework/Dime.Repositories.Sql.EntityFramework.csproj b/src/providers/EntityFramework/Dime.Repositories.Sql.EntityFramework.csproj index 5b157ea..be3f19d 100644 --- a/src/providers/EntityFramework/Dime.Repositories.Sql.EntityFramework.csproj +++ b/src/providers/EntityFramework/Dime.Repositories.Sql.EntityFramework.csproj @@ -1,9 +1,9 @@  - 2.0.2.0 - 2.0.2.0 - 2.0.2.0 + 2.0.3.0 + 2.0.3.0 + 2.0.3.0 latest @@ -24,7 +24,7 @@ Dime.Repositories.Sql.EntityFramework Entity Framework;Repository;SQL https://cdn.dime-software.com/dime-software/logo-shape.png - 2.0.2.0 + 2.0.3.0 Implementation of the repository pattern with Microsoft SQL using Entity Framework Core Copyright © 2024 https://github.com/dimesoftware/repository diff --git a/src/providers/EntityFramework/Repository/Async/CreateRepositoryAsync.cs b/src/providers/EntityFramework/Repository/Async/CreateRepositoryAsync.cs index 9095933..567b355 100644 --- a/src/providers/EntityFramework/Repository/Async/CreateRepositoryAsync.cs +++ b/src/providers/EntityFramework/Repository/Async/CreateRepositoryAsync.cs @@ -64,7 +64,7 @@ public virtual async Task> CreateAsync(IQueryable e if (!entities.Any()) return entities; - List newEntities = new(); + List newEntities = []; TContext ctx = Context; foreach (TEntity entity in entities.ToList()) { diff --git a/src/providers/EntityFramework/Repository/Async/DeleteRepositoryAsync.cs b/src/providers/EntityFramework/Repository/Async/DeleteRepositoryAsync.cs index e42e5e5..8bad1f4 100644 --- a/src/providers/EntityFramework/Repository/Async/DeleteRepositoryAsync.cs +++ b/src/providers/EntityFramework/Repository/Async/DeleteRepositoryAsync.cs @@ -10,6 +10,12 @@ namespace Dime.Repositories { public partial class EfRepository { + public virtual async Task DeleteAsync() + { + TContext ctx = Context; + await ctx.Set().ExecuteDeleteAsync(); + } + public virtual async Task DeleteAsync(object? id) { if (id is IEnumerable) @@ -91,15 +97,7 @@ public virtual async Task DeleteAsync(TEntity entity, bool commit) public virtual async Task DeleteAsync(Expression> where) { TContext ctx = Context; - IEnumerable entities = ctx.Set().With(where).AsNoTracking().ToList(); - if (entities.Any()) - { - foreach (TEntity item in entities) - ctx.Set().Attach(item); - - ctx.Set().RemoveRange(entities); - await SaveChangesAsync(ctx); - } + await ctx.Set().With(where).ExecuteDeleteAsync(); } } } \ No newline at end of file diff --git a/src/providers/EntityFramework/Repository/Sync/CreateRepository.cs b/src/providers/EntityFramework/Repository/Sync/CreateRepository.cs index bf538f1..bc845b7 100644 --- a/src/providers/EntityFramework/Repository/Sync/CreateRepository.cs +++ b/src/providers/EntityFramework/Repository/Sync/CreateRepository.cs @@ -64,7 +64,7 @@ public virtual IQueryable Create(IQueryable entities) if (!entities.Any()) return entities; - List newEntities = new(); + List newEntities = []; List entitiesToCreate = entities.ToList(); using TContext ctx = Context; foreach (TEntity entity in entitiesToCreate) diff --git a/src/providers/EntityFramework/Utilities/DataReaderExtensions.cs b/src/providers/EntityFramework/Utilities/DataReaderExtensions.cs index 8bf3a17..4da5e4e 100644 --- a/src/providers/EntityFramework/Utilities/DataReaderExtensions.cs +++ b/src/providers/EntityFramework/Utilities/DataReaderExtensions.cs @@ -9,7 +9,7 @@ internal static class DataReaderExtensions { internal static List GetRecords(this IDataReader reader) { - List result = new(); + List result = []; while (reader.Read()) { T t = (T)typeof(T).GetConstructor(Type.EmptyTypes).Invoke(Array.Empty()); diff --git a/src/providers/EntityFramework/Utilities/EFExtensions.cs b/src/providers/EntityFramework/Utilities/EFExtensions.cs index 27d8e5e..ef9f3e6 100644 --- a/src/providers/EntityFramework/Utilities/EFExtensions.cs +++ b/src/providers/EntityFramework/Utilities/EFExtensions.cs @@ -19,7 +19,7 @@ internal static IQueryable Include(this IQueryable qu if (includes == null) return query; - List includeList = new(); + List includeList = []; if (includes.Length != 0) return includes .Where(x => !string.IsNullOrEmpty(x) && !includeList.Contains(x)) diff --git a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/DeleteAsyncTests.cs b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/DeleteAsyncTests.cs index 3824a6f..70d4275 100644 --- a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/DeleteAsyncTests.cs +++ b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/DeleteAsyncTests.cs @@ -27,12 +27,26 @@ public async Task DeleteAsync_ByIds_ShouldRemoveList() using TestDatabase testDb = new(); using IRepository repo = new EfRepository(new BloggingContext(testDb.Options)); - List ids = new() { 1, 2 }; + List ids = [1, 2]; await repo.DeleteAsync(ids); // Use a separate instance of the context to verify correct data was saved to database await using BloggingContext context = new(testDb.Options); Assert.AreEqual(1, context.Blogs.Count()); } + + [TestMethod] + public async Task DeleteAsync_Bulk_ShouldRemoveList() + { + using TestDatabase testDb = new(); + using IRepository repo = new EfRepository(new BloggingContext(testDb.Options)); + + List ids = [1, 2]; + await repo.DeleteAsync(); + + // Use a separate instance of the context to verify correct data was saved to database + await using BloggingContext context = new(testDb.Options); + Assert.AreEqual(0, context.Blogs.Count()); + } } } \ No newline at end of file