diff --git a/src/core/Dime.Repositories.Sql/Dime.Repositories.Sql.csproj b/src/core/Dime.Repositories.Sql/Dime.Repositories.Sql.csproj index 13f5ebb..ccb97c3 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.3.0 - 2.0.3.0 - 2.0.3.0 + 2.1.0.0 + 2.1.0.0 + 2.1.0.0 Dime Software - 2.0.3.0 + 2.1.0.0-beta.2 Dime Software net8.0 Dime.Repositories.Sql diff --git a/src/core/Dime.Repositories/Dime.Repositories.csproj b/src/core/Dime.Repositories/Dime.Repositories.csproj index 501e91b..633fb8c 100644 --- a/src/core/Dime.Repositories/Dime.Repositories.csproj +++ b/src/core/Dime.Repositories/Dime.Repositories.csproj @@ -1,10 +1,10 @@  - 2.0.1.0 - 2.0.1.0 - 2.0.1.0 + 2.1.0.0 + 2.1.0.0 + 2.1.0.0 Dime Software - 2.0.1.0 + 2.1.0.0-beta.2 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 bb1c570..4db5244 100644 --- a/src/core/Dime.Repositories/Interfaces/Repository/IDeleteRepository.cs +++ b/src/core/Dime.Repositories/Interfaces/Repository/IDeleteRepository.cs @@ -27,7 +27,7 @@ public interface IDeleteRepository : IDisposable where TEntity : class /// /// Removes all records - /// + /// /// Task Task DeleteAsync(); diff --git a/src/core/Dime.Repositories/Interfaces/Repository/IQueryRepositoryAsync.cs b/src/core/Dime.Repositories/Interfaces/Repository/IQueryRepositoryAsync.cs index a955931..ccc8b3c 100644 --- a/src/core/Dime.Repositories/Interfaces/Repository/IQueryRepositoryAsync.cs +++ b/src/core/Dime.Repositories/Interfaces/Repository/IQueryRepositoryAsync.cs @@ -87,7 +87,6 @@ public partial interface IQueryRepositoryAsync : IDisposable where TEnt /// Indicates whether the sorting is ascending (true) or descending (false) /// The page number which is multiplied by the pagesize to calculate the amount of items to skip /// The size of the batch of items that must be retrieved - /// The optional list of related entities that should be eagerly loaded /// An instance of with the mapped data from the record that matched all filters. Task FindOneAsync( Expression> where = null, @@ -95,8 +94,7 @@ Task FindOneAsync( Expression> orderBy = null, bool? ascending = null, int? page = null, - int? pageSize = null, - params string[] includes) + int? pageSize = null) where TResult : class; /// @@ -132,7 +130,6 @@ Task FindOneAsync( /// The sorting expression to execute against the data store /// The page number which is multiplied by the pagesize to calculate the amount of items to skip /// The size of the batch of items that must be retrieved - /// The optional list of related entities that should be eagerly loaded /// An collection of with the mapped data from the records that matched all filters. IEnumerable FindAll( Expression> where = null, @@ -140,8 +137,7 @@ IEnumerable FindAll( Expression> orderBy = null, bool? ascending = null, int? page = null, - int? pageSize = null, - params string[] includes); + int? pageSize = null); /// /// Finds entities based on provided criteria. @@ -160,16 +156,15 @@ IEnumerable FindAll( /// The sorting expression to execute against the data store /// The page number which is multiplied by the pagesize to calculate the amount of items to skip /// The size of the batch of items that must be retrieved - /// The optional list of related entities that should be eagerly loaded /// An collection of with the mapped data from the records that matched all filters. Task> FindAllAsync( Expression> where = null, Expression> select = null, + Expression> selectWhere = null, Expression> orderBy = null, bool? ascending = null, int? page = null, - int? pageSize = null, - params string[] includes); + int? pageSize = null); /// /// Retrieves a collection of paged, sorted and filtered items in a flat list diff --git a/src/providers/EntityFramework/Dime.Repositories.Sql.EntityFramework.csproj b/src/providers/EntityFramework/Dime.Repositories.Sql.EntityFramework.csproj index be3f19d..31b93bb 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.3.0 - 2.0.3.0 - 2.0.3.0 + 2.1.0.0 + 2.1.0.0 + 2.1.0.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.3.0 + 2.1.0.0-beta.2 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/GetProjectedRepositoryAsync.cs b/src/providers/EntityFramework/Repository/Async/GetProjectedRepositoryAsync.cs new file mode 100644 index 0000000..29e52c2 --- /dev/null +++ b/src/providers/EntityFramework/Repository/Async/GetProjectedRepositoryAsync.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; +using LinqKit; +using Microsoft.EntityFrameworkCore; + +namespace Dime.Repositories +{ + public partial class EfRepository + { + public Task FindOneAsync( + Expression> where = null, + Expression> select = null, + Expression> orderBy = null, + bool? ascending = default, + int? page = default, + int? pageSize = default) where TResult : class + { + using TContext ctx = Context; + IQueryable query = ctx.Set() + .AsExpandable() + .AsQueryable() + .AsNoTracking() + .With(where) + .WithOrder(orderBy, ascending ?? true) + .With(page, pageSize, orderBy) + .With(pageSize) + .WithSelect(select); + + return Task.FromResult(query.FirstOrDefault()); + } + + public virtual Task> FindAllAsync( + Expression> where = null, + Expression> select = null, + Expression> orderBy = null, + bool? ascending = null, + int? page = null, + int? pageSize = null) + => FindAllAsync(where, select, null, orderBy, ascending, page, pageSize); + + public virtual Task> FindAllAsync( + Expression> where = null, + Expression> select = null, + Expression> selectWhere = null, + Expression> orderBy = null, + bool? ascending = null, + int? page = null, + int? pageSize = null) + { + using TContext ctx = Context; + IQueryable query = ctx.Set() + .AsNoTracking() + .AsExpandable() + .AsQueryable() + .With(where) + .WithOrder(orderBy, ascending ?? true) + .With(page, pageSize, orderBy) + .With(pageSize) + .WithSelect(select, selectWhere); + + return Task.FromResult(query.ToList() as IEnumerable); + } + } +} \ No newline at end of file diff --git a/src/providers/EntityFramework/Repository/Async/GetRepositoryAsync.cs b/src/providers/EntityFramework/Repository/Async/GetRepositoryAsync.cs index beb2d31..b69c383 100644 --- a/src/providers/EntityFramework/Repository/Async/GetRepositoryAsync.cs +++ b/src/providers/EntityFramework/Repository/Async/GetRepositoryAsync.cs @@ -53,30 +53,6 @@ public virtual async Task FindOneAsync(Expression> .WithFirst(where); } - public Task FindOneAsync( - Expression> where = null, - Expression> select = null, - Expression> orderBy = null, - bool? ascending = default, - int? page = default, - int? pageSize = default, - params string[] includes) where TResult : class - { - using TContext ctx = Context; - IQueryable query = ctx.Set() - .AsExpandable() - .AsQueryable() - .AsNoTracking() - .With(where) - .WithOrder(orderBy, ascending ?? true) - .With(page, pageSize, orderBy) - .With(pageSize) - .WithSelect(select) - .Include(Context, includes); - - return Task.FromResult(query.FirstOrDefault()); - } - public virtual async Task> FindAllAsync(Expression> where, params string[] includes) { TContext ctx = Context; @@ -90,30 +66,6 @@ public virtual async Task> FindAllAsync(Expression> FindAllAsync( - Expression> where = null, - Expression> select = null, - Expression> orderBy = null, - bool? ascending = null, - int? page = null, - int? pageSize = null, - params string[] includes) - { - using TContext ctx = Context; - IQueryable query = ctx.Set() - .Include(ctx, includes) - .AsNoTracking() - .AsExpandable() - .AsQueryable() - .With(where) - .WithOrder(orderBy, ascending ?? true) - .With(page, pageSize, orderBy) - .With(pageSize) - .WithSelect(select); - - return Task.FromResult(query.ToList() as IEnumerable); - } - public virtual async Task> FindAllAsync( Expression> where = null, Expression> orderBy = null, diff --git a/src/providers/EntityFramework/Repository/Sync/GetProjectedRepository.cs b/src/providers/EntityFramework/Repository/Sync/GetProjectedRepository.cs new file mode 100644 index 0000000..6160785 --- /dev/null +++ b/src/providers/EntityFramework/Repository/Sync/GetProjectedRepository.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using LinqKit; +using Microsoft.EntityFrameworkCore; + +namespace Dime.Repositories +{ + public partial class EfRepository + { + public TResult FindOne( + Expression> where = null, + Expression> select = null, + Expression> orderBy = null, + bool? ascending = default, + int? page = default, + int? pageSize = default, + params string[] includes) where TResult : class + { + using TContext ctx = Context; + IQueryable query = ctx.Set() + .AsExpandable() + .AsQueryable() + .AsNoTracking() + .With(where) + .WithOrder(orderBy, ascending ?? true) + .With(page, pageSize, orderBy) + .With(pageSize) + .WithSelect(select) + .Include(Context, includes); + + return query.FirstOrDefault(); + } + + public virtual IEnumerable FindAll( + Expression> where = null, + Expression> select = null, + Expression> orderBy = null, + bool? ascending = null, + int? page = null, + int? pageSize = null) + { + using TContext ctx = Context; + IQueryable query = ctx.Set() + .AsNoTracking() + .AsExpandable() + .With(where) + .WithOrder(orderBy, ascending ?? true) + .With(page, pageSize, orderBy) + .With(pageSize) + .WithSelect(select); + + return query.ToList(); + } + } +} \ No newline at end of file diff --git a/src/providers/EntityFramework/Repository/Sync/GetRepository.cs b/src/providers/EntityFramework/Repository/Sync/GetRepository.cs index cd33ef4..ccbec35 100644 --- a/src/providers/EntityFramework/Repository/Sync/GetRepository.cs +++ b/src/providers/EntityFramework/Repository/Sync/GetRepository.cs @@ -54,30 +54,6 @@ public virtual TEntity FindOne(Expression> where, params str return query.FirstOrDefault(); } - public TResult FindOne( - Expression> where = null, - Expression> select = null, - Expression> orderBy = null, - bool? ascending = default, - int? page = default, - int? pageSize = default, - params string[] includes) where TResult : class - { - using TContext ctx = Context; - IQueryable query = ctx.Set() - .AsExpandable() - .AsQueryable() - .AsNoTracking() - .With(where) - .WithOrder(orderBy, ascending ?? true) - .With(page, pageSize, orderBy) - .With(pageSize) - .WithSelect(select) - .Include(Context, includes); - - return query.FirstOrDefault(); - } - public IEnumerable FindAll(Expression> where) { using TContext ctx = Context; @@ -130,29 +106,6 @@ public IEnumerable FindAll(Expression> where, int? .Include(Context, includes); } - public virtual IEnumerable FindAll( - Expression> where = null, - Expression> select = null, - Expression> orderBy = null, - bool? ascending = null, - int? page = null, - int? pageSize = null, - params string[] includes) - { - using TContext ctx = Context; - IQueryable query = ctx.Set() - .Include(ctx, includes) - .AsNoTracking() - .AsExpandable() - .With(where) - .WithOrder(orderBy, ascending ?? true) - .With(page, pageSize, orderBy) - .With(pageSize) - .WithSelect(select); - - return query.ToList(); - } - public virtual IEnumerable FindAll( Expression> where = null, Expression> orderBy = null, diff --git a/src/providers/EntityFramework/Repository/Sync/PagedRepository.cs b/src/providers/EntityFramework/Repository/Sync/PagedRepository.cs index fb3e17c..2c19e58 100644 --- a/src/providers/EntityFramework/Repository/Sync/PagedRepository.cs +++ b/src/providers/EntityFramework/Repository/Sync/PagedRepository.cs @@ -223,6 +223,5 @@ public Page FindAllPaged( return new Page(query.ToList(), ctx.Count(where)); } - } } \ No newline at end of file diff --git a/src/providers/EntityFramework/Utilities/Query Factory/SelectQueryFactory.cs b/src/providers/EntityFramework/Utilities/Query Factory/SelectQueryFactory.cs index d754219..dcf5be3 100644 --- a/src/providers/EntityFramework/Utilities/Query Factory/SelectQueryFactory.cs +++ b/src/providers/EntityFramework/Utilities/Query Factory/SelectQueryFactory.cs @@ -28,6 +28,12 @@ internal static IQueryable WithSelect(this IQueryable where TSource : class => selector == null ? default : source.Select(selector).AsQueryable(); + internal static IQueryable WithSelect(this IQueryable source, + Expression> selector, + Expression> where) + where TSource : class + => selector == null ? default : where == null ? source.Select(selector).AsQueryable() : source.Select(selector).Where(where).AsQueryable(); + internal static IQueryable WithSelect(this IQueryable source, Func selector) where TSource : class diff --git a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/DeleteAsyncTests.cs b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/DeleteAsyncTests.cs index 70d4275..9d6b90a 100644 --- a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/DeleteAsyncTests.cs +++ b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/DeleteAsyncTests.cs @@ -8,7 +8,7 @@ namespace Dime.Repositories.Sql.EntityFramework.Tests { [TestClass] public partial class DeleteAsyncTests - { + { [TestMethod] public async Task DeleteAsync_ByEntity_ShouldRemoveOne() { diff --git a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/GetAsyncTests.cs b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/GetAsyncTests.cs index f6f8e91..081746c 100644 --- a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/GetAsyncTests.cs +++ b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/GetAsyncTests.cs @@ -7,7 +7,7 @@ namespace Dime.Repositories.Sql.EntityFramework.Tests { [TestClass] public partial class GetAsyncTests - { + { [TestMethod] public async Task FindAllAsync_Contains_ShouldFindMatches() { diff --git a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/Helpers/BloggingContext.cs b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/Helpers/BloggingContext.cs index f866479..2cf0ebf 100644 --- a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/Helpers/BloggingContext.cs +++ b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/Helpers/BloggingContext.cs @@ -3,7 +3,6 @@ namespace Dime.Repositories.Sql.EntityFramework.Tests { - public class BloggingContext : DbContext { public BloggingContext() diff --git a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/UpdateTests.cs b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/UpdateTests.cs index ced76fb..1f68891 100644 --- a/src/test/Dime.Repositories.Sql.EntityFramework.Tests/UpdateTests.cs +++ b/src/test/Dime.Repositories.Sql.EntityFramework.Tests/UpdateTests.cs @@ -1,4 +1,3 @@ -using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Dime.Repositories.Sql.EntityFramework.Tests