From f9f40e9420d7698a0acc14c96e904c30f24dcbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Tue, 2 Nov 2021 14:21:07 +0300 Subject: [PATCH 01/49] =?UTF-8?q?=E2=9B=8F=20Implement=20includable=20and?= =?UTF-8?q?=20selectable=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EasyRepository.EFCore.Abstractions.csproj | 6 +- .../IRepository.cs | 313 +++++++++++++++++- 2 files changed, 316 insertions(+), 3 deletions(-) diff --git a/src/EasyRepository.EFCore.Entities/EasyRepository.EFCore.Abstractions.csproj b/src/EasyRepository.EFCore.Entities/EasyRepository.EFCore.Abstractions.csproj index 053ad1a..89513df 100644 --- a/src/EasyRepository.EFCore.Entities/EasyRepository.EFCore.Abstractions.csproj +++ b/src/EasyRepository.EFCore.Entities/EasyRepository.EFCore.Abstractions.csproj @@ -1,5 +1,9 @@ - + + + + + diff --git a/src/EasyRepository.EFCore.Entities/IRepository.cs b/src/EasyRepository.EFCore.Entities/IRepository.cs index 475077b..e7fbd79 100644 --- a/src/EasyRepository.EFCore.Entities/IRepository.cs +++ b/src/EasyRepository.EFCore.Entities/IRepository.cs @@ -1,5 +1,7 @@ -using System; +using Microsoft.EntityFrameworkCore.Query; +using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; @@ -227,7 +229,7 @@ public interface IRepository /// /// PK of Entity /// - void HardDelete(TPrimaryKey id) where TEntity : EasyBaseEntity; + void HardDelete(TPrimaryKey id) where TEntity : EasyBaseEntity; /// /// This method takes and . This method performs hard delete operation by id async version. In additional this method returns @@ -492,5 +494,312 @@ public interface IRepository /// Returns /// Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity; + + + /// + /// This method provides entity queryable version. In additional this method returns + /// + /// + /// Type of Entity + /// + /// + /// Returns + /// + IQueryable GetQueryable() where TEntity : class, new(); + + /// + /// This method takes and apply filter to data source. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// The filter to apply on the Entity. + /// + /// + /// Returns + /// + IQueryable GetQueryable(Expression> filter) where TEntity : class, new(); + + /// + /// This method returns List of Entity without filter. + /// + /// + /// Type of Entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking) where TEntity : class, new(); + + /// + /// This method returns List of Entity without filter async version. + /// + /// + /// Type of Entity + /// + /// A to observe while waiting for the task to complete. + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method provides without filter get all entity but you can convert it to any object you want. + /// In additional this method takes returns + /// + /// + /// Type of Entity + /// + /// + /// Type of projected object + /// + /// + /// Select expression + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, Expression> projectExpression) where TEntity : class, new(); + + /// + /// This method takes and . This method performs without filter get all entity but you can convert it to any object you want + /// + /// + /// Type of entity + /// + /// + /// Type of projected object + /// + /// + /// Select expression + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes performs apply filter get all entity. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Where expression see + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, Expression> whereExpression) where TEntity : class, new(); + + /// + /// This method takes and . This method performs apply filter get all entity. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Where Expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes where expression and select expression. This method performs apply filter and convert returns get all entity. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Type of Projected object + /// + /// + /// Where Expression + /// + /// + /// Select expression + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new(); + + /// + /// This method takes where expression and select expression. This method performs apply filter async version and convert returns get all entity. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Type of Projected object + /// + /// + /// Where Expression + /// + /// + /// Select expression + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes and . This method performs get all with includable entities. In additional this method returns + /// + /// + /// Type of Entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// expression + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, IIncludableQueryable includeExpression) where TEntity : class, new(); + + /// + /// This method takes and . This method performs get all with includable entities async version. In additional this method returns + /// + /// + /// Type of Entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes , and . This method perform get all entities with filter and includable entities. In additional this method returns + /// + /// + /// Type of Entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where Expression + /// + /// + /// Include expression + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression) where TEntity : class, new(); + + /// + /// This method takes , , and . This method perform get all entities with filter and includable entities async version. In additional this method returns + /// + /// + /// Type of Entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where Expression + /// + /// + /// Include expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, where expression, include expression and select expression. This method perform get all projected object with filter and include entities. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where Expression + /// + /// + /// Include expression + /// + /// + /// Select expression + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, Expression> projectExpression) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, where expression, include expression, select expression and cancellation token. This method perform get all projected object with filter and include entities async version. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where Expression + /// + /// + /// Include expression + /// + /// + /// Select expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); } } From 46e631443c79a2fc8b393a5f7574e1b4e8cfeed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 6 Nov 2021 22:40:06 +0300 Subject: [PATCH 02/49] =?UTF-8?q?=E2=9B=8F=20Implemented=20Get=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EasyRepository.EFCore.Abstractions.csproj | 1 + .../IRepository.cs | 560 +++++++++++++++++- 2 files changed, 560 insertions(+), 1 deletion(-) diff --git a/src/EasyRepository.EFCore.Entities/EasyRepository.EFCore.Abstractions.csproj b/src/EasyRepository.EFCore.Entities/EasyRepository.EFCore.Abstractions.csproj index 89513df..aa691c8 100644 --- a/src/EasyRepository.EFCore.Entities/EasyRepository.EFCore.Abstractions.csproj +++ b/src/EasyRepository.EFCore.Entities/EasyRepository.EFCore.Abstractions.csproj @@ -3,6 +3,7 @@ + diff --git a/src/EasyRepository.EFCore.Entities/IRepository.cs b/src/EasyRepository.EFCore.Entities/IRepository.cs index e7fbd79..21ac96a 100644 --- a/src/EasyRepository.EFCore.Entities/IRepository.cs +++ b/src/EasyRepository.EFCore.Entities/IRepository.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore.Query; +using AutoFilterer.Types; +using Microsoft.EntityFrameworkCore.Query; using System; using System.Collections.Generic; using System.Linq; @@ -801,5 +802,562 @@ public interface IRepository /// Returns /// Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, pagination filter object. This method performs generate LINQ expressions for Entities over DTOs automatically. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of filter object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter dto + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, TFilter filter) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, pagination filter object and . This method performs generate LINQ expressions for Entities over DTOs automatically async version. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of filter object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter dto + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, pagination filter object and include expression. This method performs get all entities with apply filter and includable entities. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Type of filter Object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter dto + /// + /// + /// Include expression + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, paginationable filter object, and cancellation token. This method performs get all entities with apply filter and get all includable entities async version. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Type of filter object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter dto + /// + /// + /// Include expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, paginationable filter object and project expression. This method performs get all projected objects with apply filter. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Type of filter Object + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter dto + /// + /// + /// Project expression + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, paginationable filter object and project expression. This method performs get all projected objects with apply filter async version. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Type of filter Object + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter dto + /// + /// + /// Project expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, paginationable filter object, project expression and include expression. This method performs get all projected objects with apply filter and get all includable entities. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Type of filter + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter dto + /// + /// + /// Project expression + /// + /// + /// Include expression + /// + /// + /// Returns + /// + List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, paginationable filter object, project expression and include expression. This method performs get all projected objects with apply filter and get all includable entities async version. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Type of filter + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter dto + /// + /// + /// Project expression + /// + /// + /// Include expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + + + /// + /// This method takes asNoTracking and where expression. This method performs get entity with apply filter. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where expression + /// + /// + /// Returns + /// + TEntity GetSingle(bool asNoTracking, Expression> whereExpression) where TEntity : class, new(); + + /// + /// This method takes asNoTracking and where expression. This method performs get entity with apply filter async version. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, and include expression. This method performs get entity with apply filter and includable entities. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where expression + /// + /// + /// Include expression + /// + /// + /// Returns + /// + TEntity GetSingle(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, and include expression. This method performs get entity with apply filter and includable entities async version. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where expression + /// + /// + /// Include expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, where expression and project the expression. This method performs get projected object with apply filter. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where expression + /// + /// + /// Project expression + /// + /// + /// Returns + /// + TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, where expression, project the expression and cancellation token. This method performs get projected object with apply filter async version. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where expression + /// + /// + /// Project expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, where expression, project expression and include expression. This method performs get projected object with apply filter and includable entity. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where expression + /// + /// + /// Project expression + /// + /// + /// Include expression + /// + /// + /// Returns + /// + TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, IIncludableQueryable includeExpression) where TEntity : class, new(); + + + /// + /// This method takes asNoTracking, where expression, project expression, include expression and cancellation token. This method performs get projected object with apply filter and includable entity async version. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Where expression + /// + /// + /// Project expression + /// + /// + /// Include expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + + /// + /// This method takes asNoTracking and id. This method provides get entity by id. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// PK of entity + /// + /// + /// Returns + /// + TEntity GetById(bool asNoTracking, object id) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, id. This method provides get entity by id async version. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// PK of entity + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetByIdAsync(bool asNoTracking, object id, CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, id and include expression. This method performs get entity by id with includable entities. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Do you want the entity to be tracked by the EF Core? Default value : false + /// + /// + /// PK of entity + /// + /// + /// Include expression + /// + /// + /// Returns + /// + TEntity GetById(bool asNoTracking, object id, IIncludableQueryable includeExpression) where TEntity : class, new(); + + /// + /// This method takes asNoTracking, id, include expression and cancellation token. This method performs get entity by id with includable entities. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Do you want the entity to be tracked by the EF Core? Default value : false + /// + /// + /// PK of entity + /// + /// + /// Include expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + TEntity GetByIdAsync(bool asNoTracking, object id, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + + /// + /// This method takes asnoTracking, id and project expression. This method performs get projected object by id with includable entities. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by the EF Core? Default value : false + /// + /// + /// PK of entity + /// + /// + /// Project expression + /// + /// + /// Returns + /// + TProjected GetById(bool asNoTracking, object id, Expression> projectExpression) where TEntity : class, new(); + + /// + /// This method takes asnoTracking, id and project expression. This method performs get projected object by id with includable entities async version. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by the EF Core? Default value : false + /// + /// + /// PK of entity + /// + /// + /// Project expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetByIdAsync(bool asNoTracking, object id, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + + /// + /// This method takes asnoTracking, id, and project expression. This method performs get projected object by id with includable entities. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by the EF Core? Default value : false + /// + /// + /// PK of entity + /// + /// + /// Include expression + /// + /// + /// Project expression + /// + /// + /// Returns + /// + TProjected GetById(bool asNoTracking, object id, IIncludableQueryable includeExpression, Expression> projectExpression) where TEntity : class, new(); + + /// + /// This method takes asnoTracking, id, and project expression. This method performs get projected object by id with includable entities async version. In additional this method returns + /// + /// + /// Type of entity + /// + /// + /// Type of projected object + /// + /// + /// Do you want the entity to be tracked by the EF Core? Default value : false + /// + /// + /// PK of entity + /// + /// + /// Include expression + /// + /// + /// Project expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetByIdAsync(bool asNoTracking, object id, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); } } From ff1abfdcca7461ad918121cfd67619ce0fc5455a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 6 Nov 2021 23:48:30 +0300 Subject: [PATCH 03/49] =?UTF-8?q?=E2=9B=8F=20Implement=20get=20single=20en?= =?UTF-8?q?dpoint=20by=20AutoFilterer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRepository.cs | 180 +++++++++++++++++- 1 file changed, 178 insertions(+), 2 deletions(-) diff --git a/src/EasyRepository.EFCore.Entities/IRepository.cs b/src/EasyRepository.EFCore.Entities/IRepository.cs index 21ac96a..c2d6866 100644 --- a/src/EasyRepository.EFCore.Entities/IRepository.cs +++ b/src/EasyRepository.EFCore.Entities/IRepository.cs @@ -1099,7 +1099,7 @@ public interface IRepository /// Project expression /// /// - /// Returns + /// Returns /// TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new(); @@ -1123,7 +1123,7 @@ public interface IRepository /// /// A to observe while waiting for the task to complete. /// - /// Returns + /// Returns /// Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); @@ -1181,6 +1181,182 @@ public interface IRepository /// Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + /// + /// This method takes asNoTracking and filter object. This object must be type . This method perform get entity with filter. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of Filter + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter object of type FilterBase + /// + /// + /// Returns + /// + TEntity GetSingle(bool asNoTracking, TFilter filter) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, cancellation token and filter object. This object must be type . This method perform get entity with filter async version. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of Filter + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter object of type FilterBase + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetSingleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, include expression and filterable object . This method performs get and includable entity with filter. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of Filter + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter object of type FilterBase + /// + /// + /// Include expression + /// + /// + /// Returns + /// + TEntity GetSingle(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, include expression, cancellation token and filterable object . This method performs get and includable entity with filter. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of Filter + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter object of type FilterBase + /// + /// + /// Include expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetSingleAsync(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, select expression and filterable object . This method performs get projected object with filter. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of Filter + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter object of type FilterBase + /// + /// + /// Returns + /// + TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, select expression, cancellation token and filterable object . This method performs get projected object with filter. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of Filter + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter object of type FilterBase + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, select expression, include expression and filterable object . This method performs get projected object with filter. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of Filter + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter object of type FilterBase + /// + /// + /// Include expression + /// + /// + /// Returns + /// + TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes asNoTracking, select expression, include expression, cancellation token and filterable object . This method performs get projected object with filter. In additional returns + /// + /// + /// Type of Entity + /// + /// + /// Type of Filter + /// + /// + /// Do you want the entity to be tracked by EF Core? Default value : false + /// + /// + /// Filter object of type FilterBase + /// + /// + /// Include expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + /// /// This method takes asNoTracking and id. This method provides get entity by id. In additional returns From 2d578a415142526aee902ca76733672d7caf3777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 7 Nov 2021 21:34:06 +0300 Subject: [PATCH 04/49] =?UTF-8?q?=E2=9B=8F=20Implement=20any=20operation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRepository.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/EasyRepository.EFCore.Entities/IRepository.cs b/src/EasyRepository.EFCore.Entities/IRepository.cs index c2d6866..dcc0849 100644 --- a/src/EasyRepository.EFCore.Entities/IRepository.cs +++ b/src/EasyRepository.EFCore.Entities/IRepository.cs @@ -1535,5 +1535,35 @@ public interface IRepository /// Returns /// Task GetByIdAsync(bool asNoTracking, object id, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + + /// + /// This method takes any expression. This method perform exist operation for condition. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Any expression + /// + /// + /// Returns + /// + bool Any(Expression> anyExpression) where TEntity : class, new(); + + /// + /// This method takes any expression and cancellation token. This method perform exist operation for condition. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Any expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task AnyAsync(Expression> anyExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); } } From de4130cef95ac53a2a9c6226f7df1bfa91cd120c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 7 Nov 2021 21:55:01 +0300 Subject: [PATCH 05/49] =?UTF-8?q?=E2=9B=8F=20Implement=20count=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRepository.cs | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/src/EasyRepository.EFCore.Entities/IRepository.cs b/src/EasyRepository.EFCore.Entities/IRepository.cs index dcc0849..db0c303 100644 --- a/src/EasyRepository.EFCore.Entities/IRepository.cs +++ b/src/EasyRepository.EFCore.Entities/IRepository.cs @@ -1565,5 +1565,94 @@ public interface IRepository /// Returns /// Task AnyAsync(Expression> anyExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + + /// + /// This method performs get count information of entity. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Returns + /// + int Count() where TEntity : class, new(); + + /// + /// This method takes cancellation token.This method performs get count information of entity async version. In additional returns + /// + /// + /// Type of entity + /// + /// + /// A to observe while waiting for the task to complete. + /// Returns + /// + Task CountAsync(CancellationToken cancellationToken = default) where TEntity : class, new(); + + /// + /// This method takes . This method performs get count information of entity with filter. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Where expression + /// + /// + /// Returns + /// + int Count(Expression> whereExpression) where TEntity : class, new(); + + /// + /// This method takes and cancellation token. This method performs get count information of entity with filter async version. In additional returns + /// + /// + /// Type of entity + /// + /// + /// Where expression + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task Count(Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + + + /// + /// This method takes filterable object. This object must be inheritance . This method performs get count information of entity with filter. In additional + /// + /// + /// Type of Entity + /// + /// + /// Type of filterable object + /// + /// + /// Filterable object + /// + /// + /// Returns + /// + int Count(TFilter filter) where TEntity : class, new() where TFilter : FilterBase; + + /// + /// This method takes cancellation token and filterable object. This object must be inheritance . This method performs get count information of entity with filter async version. In additional + /// + /// + /// Type of Entity + /// + /// + /// Type of filterable object + /// + /// + /// Filterable object + /// + /// A to observe while waiting for the task to complete. + /// + /// Returns + /// + Task CountAsync(TFilter filter, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; } } From 8e23e017f2ac97f74da6e0e5c80311a421d9331a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 7 Nov 2021 22:21:04 +0300 Subject: [PATCH 06/49] =?UTF-8?q?=E2=9B=8F=20Implement=20add=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EasyRepository.EFCore.Generic.csproj | 4 + .../Repository.cs | 519 ++++++++++++++++++ 2 files changed, 523 insertions(+) create mode 100644 src/EasyRepository.EFCore.Generic/Repository.cs diff --git a/src/EasyRepository.EFCore.Generic/EasyRepository.EFCore.Generic.csproj b/src/EasyRepository.EFCore.Generic/EasyRepository.EFCore.Generic.csproj index 053ad1a..6871b29 100644 --- a/src/EasyRepository.EFCore.Generic/EasyRepository.EFCore.Generic.csproj +++ b/src/EasyRepository.EFCore.Generic/EasyRepository.EFCore.Generic.csproj @@ -2,4 +2,8 @@ + + + + diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs new file mode 100644 index 0000000..5ed8968 --- /dev/null +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -0,0 +1,519 @@ +using AutoFilterer.Types; +using EasyRepository.EFCore.Abstractions; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Query; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace EasyRepository.EFCore.Generic +{ + /// + /// This class includes implementations of repository functions + /// + internal class Repository : IRepository + { + private readonly DbContext context; + + /// + /// Ctor + /// + /// + /// Database Context + /// + public Repository(DbContext context) + { + this.context = context; + } + + public virtual TEntity Add(TEntity entity) where TEntity : class, new() + { + context.Set().Add(entity); + context.SaveChanges(); + return entity; + } + + public virtual TEntity Add(TEntity entity) where TEntity : EasyBaseEntity + { + entity.CreationDate = DateTime.UtcNow; + context.Set().Add(entity); + context.SaveChanges(); + return entity; + } + + public virtual async Task AddAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + { + await context.Set().AddAsync(entity, cancellationToken).ConfigureAwait(false); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entity; + } + + public virtual async Task AddAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + { + entity.CreationDate = DateTime.UtcNow; + await context.Set().AddAsync(entity, cancellationToken).ConfigureAwait(false); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entity; + } + + public IEnumerable AddRange(IEnumerable entities) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public IEnumerable AddRange(IEnumerable entities) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public Task> AddRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task> AddRangeAsync(IEnumerable entites, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public bool Any(Expression> anyExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task AnyAsync(Expression> anyExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public int Count() where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public int Count(Expression> whereExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task Count(Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public int Count(TFilter filter) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public Task CountAsync(CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task CountAsync(TFilter filter, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public TEntity GetById(bool asNoTracking, object id) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TEntity GetById(bool asNoTracking, object id, IIncludableQueryable includeExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TProjected GetById(bool asNoTracking, object id, Expression> projectExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TProjected GetById(bool asNoTracking, object id, IIncludableQueryable includeExpression, Expression> projectExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task GetByIdAsync(bool asNoTracking, object id, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TEntity GetByIdAsync(bool asNoTracking, object id, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task GetByIdAsync(bool asNoTracking, object id, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task GetByIdAsync(bool asNoTracking, object id, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, Expression> projectExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, IIncludableQueryable includeExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, Expression> projectExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, TFilter filter) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public IQueryable GetQueryable() where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public IQueryable GetQueryable(Expression> filter) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TEntity GetSingle(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TEntity GetSingle(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, IIncludableQueryable includeExpression) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TEntity GetSingle(bool asNoTracking, TFilter filter) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public TEntity GetSingle(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task GetSingleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public Task GetSingleAsync(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase + { + throw new NotImplementedException(); + } + + public void HardDelete(TEntity entity) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public void HardDelete(object id) + { + throw new NotImplementedException(); + } + + public void HardDelete(TEntity entity) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public void HardDelete(TPrimaryKey id) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task HardDeleteAsync(object id, CancellationToken cancellationToken = default) + { + throw new NotImplementedException(); + } + + public Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public Task HardDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public TEntity Replace(TEntity entity) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TEntity Replace(TEntity entity) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public void SoftDelete(TEntity entity) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public void SoftDelete(TPrimaryKey id) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public Task SoftDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public Task SoftDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public TEntity Update(TEntity entity) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public TEntity Update(TEntity entity) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public IEnumerable UpdateRange(IEnumerable entities) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public IEnumerable UpdateRange(IEnumerable entities) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + + public Task> UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : class, new() + { + throw new NotImplementedException(); + } + + public Task> UpdateRangeAsync(IEnumerable entites, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + { + throw new NotImplementedException(); + } + } +} From 369a5c567444efc3409915a9f8ecc51be601a8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 7 Nov 2021 22:33:54 +0300 Subject: [PATCH 07/49] =?UTF-8?q?=E2=9B=8F=20Implement=20add=20range=20end?= =?UTF-8?q?points?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 5ed8968..87fbada 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -60,24 +60,34 @@ public virtual async Task AddAsync(TEntity entity return entity; } - public IEnumerable AddRange(IEnumerable entities) where TEntity : class, new() + public virtual IEnumerable AddRange(IEnumerable entities) where TEntity : class, new() { - throw new NotImplementedException(); + context.Set().AddRange(entities); + context.SaveChanges(); + return entities; } - public IEnumerable AddRange(IEnumerable entities) where TEntity : EasyBaseEntity + public virtual IEnumerable AddRange(IEnumerable entities) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entities.ToList().ForEach(x => x.CreationDate = DateTime.UtcNow); + context.Set().AddRange(entities); + context.SaveChanges(); + return entities; } - public Task> AddRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task> AddRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + await context.Set().AddRangeAsync(entities, cancellationToken).ConfigureAwait(false); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entities; } - public Task> AddRangeAsync(IEnumerable entites, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public virtual async Task> AddRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entities.ToList().ForEach(x => x.CreationDate = DateTime.UtcNow); + await context.Set().AddRangeAsync(entities, cancellationToken).ConfigureAwait(false); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entities; } public bool Any(Expression> anyExpression) where TEntity : class, new() From 5e00865aba44d6d3007f5f7edb9c8050090465ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 7 Nov 2021 22:37:01 +0300 Subject: [PATCH 08/49] =?UTF-8?q?=E2=9B=8F=20Implement=20any=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/EasyRepository.EFCore.Generic/Repository.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 87fbada..9199d9f 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -90,14 +90,15 @@ public virtual async Task> AddRangeAsync(Expression> anyExpression) where TEntity : class, new() + public virtual bool Any(Expression> anyExpression) where TEntity : class, new() { - throw new NotImplementedException(); + return context.Set().Any(anyExpression); } - public Task AnyAsync(Expression> anyExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task AnyAsync(Expression> anyExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + bool result = await context.Set().AnyAsync(anyExpression, cancellationToken).ConfigureAwait(false); + return result; } public int Count() where TEntity : class, new() From 61df641ca126d711762fe4130145a9babe7dd6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 7 Nov 2021 22:41:44 +0300 Subject: [PATCH 09/49] =?UTF-8?q?=E2=9B=8F=20Implement=20count=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository.cs | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 9199d9f..bb9381d 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -1,4 +1,5 @@ -using AutoFilterer.Types; +using AutoFilterer.Extensions; +using AutoFilterer.Types; using EasyRepository.EFCore.Abstractions; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Query; @@ -101,38 +102,41 @@ public virtual async Task> AddRangeAsync() where TEntity : class, new() + public virtual int Count() where TEntity : class, new() { - throw new NotImplementedException(); + return context.Set().Count(); } - public int Count(Expression> whereExpression) where TEntity : class, new() + public virtual int Count(Expression> whereExpression) where TEntity : class, new() { - throw new NotImplementedException(); + return context.Set().Where(whereExpression).Count(); } - public Task Count(Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task Count(Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + int count = await context.Set().Where(whereExpression).CountAsync(cancellationToken).ConfigureAwait(false); + return count; } - public int Count(TFilter filter) + public virtual int Count(TFilter filter) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + return context.Set().ApplyFilter(filter).Count(); } - public Task CountAsync(CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task CountAsync(CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + int count = await context.Set().CountAsync(cancellationToken).ConfigureAwait(false); + return count; } - public Task CountAsync(TFilter filter, CancellationToken cancellationToken = default) + public virtual async Task CountAsync(TFilter filter, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + int count = await context.Set().ApplyFilter(filter).CountAsync(cancellationToken).ConfigureAwait(false); + return count; } public TEntity GetById(bool asNoTracking, object id) where TEntity : class, new() From dd6c6b5ca84d3c0333cfa9c34711e0e04dd15eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 14 Nov 2021 20:34:31 +0300 Subject: [PATCH 10/49] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20include?= =?UTF-8?q?=20query?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRepository.cs | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/EasyRepository.EFCore.Entities/IRepository.cs b/src/EasyRepository.EFCore.Entities/IRepository.cs index db0c303..abb218c 100644 --- a/src/EasyRepository.EFCore.Entities/IRepository.cs +++ b/src/EasyRepository.EFCore.Entities/IRepository.cs @@ -171,7 +171,7 @@ public interface IRepository /// /// PK of Entity /// - void HardDelete(object id); + void HardDelete(object id) where TEntity : class, new(); /// /// This method takes an . This method performs hard delete operation async version. In additional returns @@ -689,7 +689,7 @@ public interface IRepository /// /// Returns /// - List GetMultiple(bool asNoTracking, IIncludableQueryable includeExpression) where TEntity : class, new(); + List GetMultiple(bool asNoTracking, Func, IIncludableQueryable> includeExpression) where TEntity : class, new(); /// /// This method takes and . This method performs get all with includable entities async version. In additional this method returns @@ -707,7 +707,7 @@ public interface IRepository /// /// Returns /// - Task> GetMultipleAsync(bool asNoTracking, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + Task> GetMultipleAsync(bool asNoTracking, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); /// /// This method takes , and . This method perform get all entities with filter and includable entities. In additional this method returns @@ -727,7 +727,7 @@ public interface IRepository /// /// Returns /// - List GetMultiple(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression) where TEntity : class, new(); + List GetMultiple(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new(); /// /// This method takes , , and . This method perform get all entities with filter and includable entities async version. In additional this method returns @@ -748,7 +748,7 @@ public interface IRepository /// /// Returns /// - Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); /// /// This method takes asNoTracking, where expression, include expression and select expression. This method perform get all projected object with filter and include entities. In additional returns @@ -774,7 +774,7 @@ public interface IRepository /// /// Returns /// - List GetMultiple(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, Expression> projectExpression) where TEntity : class, new(); + List GetMultiple(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, Expression> projectExpression) where TEntity : class, new(); /// /// This method takes asNoTracking, where expression, include expression, select expression and cancellation token. This method perform get all projected object with filter and include entities async version. In additional returns @@ -801,7 +801,7 @@ public interface IRepository /// /// Returns /// - Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); /// /// This method takes asNoTracking, pagination filter object. This method performs generate LINQ expressions for Entities over DTOs automatically. In additional returns @@ -865,7 +865,7 @@ public interface IRepository /// /// Returns /// - List GetMultiple(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression) where TEntity : class, new() where TFilter : FilterBase; + List GetMultiple(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() where TFilter : FilterBase; /// /// This method takes asNoTracking, paginationable filter object, and cancellation token. This method performs get all entities with apply filter and get all includable entities async version. In additional this method returns @@ -889,7 +889,7 @@ public interface IRepository /// /// Returns /// - Task> GetMultipleAsync(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; /// /// This method takes asNoTracking, paginationable filter object and project expression. This method performs get all projected objects with apply filter. In additional returns @@ -971,7 +971,7 @@ public interface IRepository /// /// Returns /// - List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression) where TEntity : class, new() where TFilter : FilterBase; + List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() where TFilter : FilterBase; /// /// This method takes asNoTracking, paginationable filter object, project expression and include expression. This method performs get all projected objects with apply filter and get all includable entities async version. In additional this method returns @@ -1001,7 +1001,7 @@ public interface IRepository /// /// Returns /// - Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; /// @@ -1057,7 +1057,7 @@ public interface IRepository /// /// Returns /// - TEntity GetSingle(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression) where TEntity : class, new(); + TEntity GetSingle(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new(); /// /// This method takes asNoTracking, and include expression. This method performs get entity with apply filter and includable entities async version. In additional this method returns @@ -1078,7 +1078,7 @@ public interface IRepository /// /// Returns /// - Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); /// /// This method takes asNoTracking, where expression and project the expression. This method performs get projected object with apply filter. In additional returns @@ -1151,7 +1151,7 @@ public interface IRepository /// /// Returns /// - TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, IIncludableQueryable includeExpression) where TEntity : class, new(); + TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new(); /// @@ -1179,7 +1179,7 @@ public interface IRepository /// /// Returns /// - Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); /// /// This method takes asNoTracking and filter object. This object must be type . This method perform get entity with filter. In additional returns @@ -1243,7 +1243,7 @@ public interface IRepository /// /// Returns /// - TEntity GetSingle(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression) where TEntity : class, new() where TFilter : FilterBase; + TEntity GetSingle(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() where TFilter : FilterBase; /// /// This method takes asNoTracking, include expression, cancellation token and filterable object . This method performs get and includable entity with filter. In additional returns @@ -1267,7 +1267,7 @@ public interface IRepository /// /// Returns /// - Task GetSingleAsync(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + Task GetSingleAsync(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; /// /// This method takes asNoTracking, select expression and filterable object . This method performs get projected object with filter. In additional returns @@ -1331,7 +1331,7 @@ public interface IRepository /// /// Returns /// - TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression) where TEntity : class, new() where TFilter : FilterBase; + TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() where TFilter : FilterBase; /// /// This method takes asNoTracking, select expression, include expression, cancellation token and filterable object . This method performs get projected object with filter. In additional returns @@ -1355,7 +1355,7 @@ public interface IRepository /// /// Returns /// - Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; + Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase; /// @@ -1411,7 +1411,7 @@ public interface IRepository /// /// Returns /// - TEntity GetById(bool asNoTracking, object id, IIncludableQueryable includeExpression) where TEntity : class, new(); + TEntity GetById(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression) where TEntity : class, new(); /// /// This method takes asNoTracking, id, include expression and cancellation token. This method performs get entity by id with includable entities. In additional this method returns @@ -1432,7 +1432,7 @@ public interface IRepository /// /// Returns /// - TEntity GetByIdAsync(bool asNoTracking, object id, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + TEntity GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); /// @@ -1507,7 +1507,7 @@ public interface IRepository /// /// Returns /// - TProjected GetById(bool asNoTracking, object id, IIncludableQueryable includeExpression, Expression> projectExpression) where TEntity : class, new(); + TProjected GetById(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, Expression> projectExpression) where TEntity : class, new(); /// /// This method takes asnoTracking, id, and project expression. This method performs get projected object by id with includable entities async version. In additional this method returns @@ -1534,7 +1534,7 @@ public interface IRepository /// /// Returns /// - Task GetByIdAsync(bool asNoTracking, object id, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + Task GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); /// @@ -1549,7 +1549,7 @@ public interface IRepository /// /// Returns /// - bool Any(Expression> anyExpression) where TEntity : class, new(); + bool Any(Expression> anyExpression) where TEntity : class, new(); /// /// This method takes any expression and cancellation token. This method perform exist operation for condition. In additional returns From b1f67bff5c92481d805f05914e4601e5290ae72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 14 Nov 2021 20:34:53 +0300 Subject: [PATCH 11/49] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20include?= =?UTF-8?q?=20query=20and=20implemented=20delete=20operations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository.cs | 228 ++++++++++-------- 1 file changed, 127 insertions(+), 101 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index bb9381d..0a38d63 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -2,9 +2,11 @@ using AutoFilterer.Types; using EasyRepository.EFCore.Abstractions; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Text; @@ -139,394 +141,418 @@ public virtual async Task CountAsync(TFilter filter, Canc return count; } - public TEntity GetById(bool asNoTracking, object id) where TEntity : class, new() + private Expression> GenerateExpression(object id) { - throw new NotImplementedException(); + var type = context.Model.FindEntityType(typeof(TEntity)); + string pk = type.FindPrimaryKey().Properties.Select(s => s.Name).FirstOrDefault(); + Type pkType = type.FindPrimaryKey().Properties.Select(p => p.ClrType).FirstOrDefault(); + + object value = Convert.ChangeType(id, pkType, CultureInfo.InvariantCulture); + + ParameterExpression pe = Expression.Parameter(typeof(TEntity), "entity"); + MemberExpression me = Expression.Property(pe, pk); + ConstantExpression constant = Expression.Constant(value, pkType); + BinaryExpression body = Expression.Equal(me, constant); + Expression> expression = Expression.Lambda>(body, new[] { pe }); + + return expression; } - public TEntity GetById(bool asNoTracking, object id, IIncludableQueryable includeExpression) where TEntity : class, new() + public void HardDelete(TEntity entity) where TEntity : class, new() { - throw new NotImplementedException(); + context.Set().Remove(entity); + context.SaveChanges(); } - public TProjected GetById(bool asNoTracking, object id, Expression> projectExpression) where TEntity : class, new() + public void HardDelete(object id) where TEntity : class, new() { - throw new NotImplementedException(); + var entity = context.Set().Find(id); + context.Set().Remove(entity); + context.SaveChanges(); } - public TProjected GetById(bool asNoTracking, object id, IIncludableQueryable includeExpression, Expression> projectExpression) where TEntity : class, new() + public void HardDelete(TEntity entity) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + context.Set().Remove(entity); + context.SaveChanges(); } - public Task GetByIdAsync(bool asNoTracking, object id, CancellationToken cancellationToken = default) where TEntity : class, new() + public void HardDelete(TPrimaryKey id) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + var entity = context.Set().FirstOrDefault(GenerateExpression(id)); + context.Set().Remove(entity); + context.SaveChanges(); + } + + public async Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + { + context.Set().Remove(entity); + await context.SaveChangesAsync(cancellationToken); } - public TEntity GetByIdAsync(bool asNoTracking, object id, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public Task HardDeleteAsync(object id, CancellationToken cancellationToken = default) { throw new NotImplementedException(); } - public Task GetByIdAsync(bool asNoTracking, object id, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public Task GetByIdAsync(bool asNoTracking, object id, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public Task HardDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking) where TEntity : class, new() + public TEntity Replace(TEntity entity) where TEntity : class, new() { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, Expression> projectExpression) where TEntity : class, new() + public TEntity Replace(TEntity entity) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() + public Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() + public Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, IIncludableQueryable includeExpression) where TEntity : class, new() + public void SoftDelete(TEntity entity) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression) where TEntity : class, new() + public void SoftDelete(TPrimaryKey id) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, Expression> projectExpression) where TEntity : class, new() + public Task SoftDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, TFilter filter) - where TEntity : class, new() - where TFilter : FilterBase + public Task SoftDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression) - where TEntity : class, new() - where TFilter : FilterBase + public TEntity Update(TEntity entity) where TEntity : class, new() { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression) - where TEntity : class, new() - where TFilter : FilterBase + public TEntity Update(TEntity entity) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression) - where TEntity : class, new() - where TFilter : FilterBase + public Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, CancellationToken cancellationToken = default) where TEntity : class, new() + public Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public IEnumerable UpdateRange(IEnumerable entities) where TEntity : class, new() { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public IEnumerable UpdateRange(IEnumerable entities) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public Task> UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public Task> UpdateRangeAsync(IEnumerable entites, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public IQueryable GetQueryable() where TEntity : class, new() { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public IQueryable GetQueryable(Expression> filter) where TEntity : class, new() { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) - where TEntity : class, new() - where TFilter : FilterBase + public List GetMultiple(bool asNoTracking) where TEntity : class, new() { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) - where TEntity : class, new() - where TFilter : FilterBase + public Task> GetMultipleAsync(bool asNoTracking, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) - where TEntity : class, new() - where TFilter : FilterBase + public List GetMultiple(bool asNoTracking, Expression> projectExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) - where TEntity : class, new() - where TFilter : FilterBase + public Task> GetMultipleAsync(bool asNoTracking, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public IQueryable GetQueryable() where TEntity : class, new() + public List GetMultiple(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public IQueryable GetQueryable(Expression> filter) where TEntity : class, new() + public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public TEntity GetSingle(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() + public List GetMultiple(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public TEntity GetSingle(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression) where TEntity : class, new() + public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() + public List GetMultiple(bool asNoTracking, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, IIncludableQueryable includeExpression) where TEntity : class, new() + public Task> GetMultipleAsync(bool asNoTracking, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public TEntity GetSingle(bool asNoTracking, TFilter filter) - where TEntity : class, new() - where TFilter : FilterBase + public List GetMultiple(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public TEntity GetSingle(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression) - where TEntity : class, new() - where TFilter : FilterBase + public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression) - where TEntity : class, new() - where TFilter : FilterBase + public List GetMultiple(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, Expression> projectExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression) - where TEntity : class, new() - where TFilter : FilterBase + public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public List GetMultiple(bool asNoTracking, TFilter filter) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public List GetMultiple(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public Task GetSingleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) + public List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression) where TEntity : class, new() where TFilter : FilterBase { throw new NotImplementedException(); } - public Task GetSingleAsync(bool asNoTracking, TFilter filter, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) + public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { throw new NotImplementedException(); } - public Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) + public List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() where TFilter : FilterBase { throw new NotImplementedException(); } - public Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, IIncludableQueryable includeExpression, CancellationToken cancellationToken = default) + public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { throw new NotImplementedException(); } - public void HardDelete(TEntity entity) where TEntity : class, new() + public TEntity GetSingle(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public void HardDelete(object id) + public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public void HardDelete(TEntity entity) where TEntity : EasyBaseEntity + public TEntity GetSingle(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public void HardDelete(TPrimaryKey id) where TEntity : EasyBaseEntity + public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + public TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public Task HardDeleteAsync(object id, CancellationToken cancellationToken = default) + public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public Task HardDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public TEntity Replace(TEntity entity) where TEntity : class, new() + public TEntity GetSingle(bool asNoTracking, TFilter filter) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public TEntity Replace(TEntity entity) where TEntity : EasyBaseEntity + public Task GetSingleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + public TEntity GetSingle(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public Task GetSingleAsync(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public void SoftDelete(TEntity entity) where TEntity : EasyBaseEntity + public TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public void SoftDelete(TPrimaryKey id) where TEntity : EasyBaseEntity + public Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public Task SoftDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public Task SoftDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) + where TEntity : class, new() + where TFilter : FilterBase { throw new NotImplementedException(); } - public TEntity Update(TEntity entity) where TEntity : class, new() + public TEntity GetById(bool asNoTracking, object id) where TEntity : class, new() { throw new NotImplementedException(); } - public TEntity Update(TEntity entity) where TEntity : EasyBaseEntity + public Task GetByIdAsync(bool asNoTracking, object id, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + public TEntity GetById(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public TEntity GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public IEnumerable UpdateRange(IEnumerable entities) where TEntity : class, new() + public TProjected GetById(bool asNoTracking, object id, Expression> projectExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public IEnumerable UpdateRange(IEnumerable entities) where TEntity : EasyBaseEntity + public Task GetByIdAsync(bool asNoTracking, object id, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } - public Task> UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : class, new() + public TProjected GetById(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, Expression> projectExpression) where TEntity : class, new() { throw new NotImplementedException(); } - public Task> UpdateRangeAsync(IEnumerable entites, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public Task GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { throw new NotImplementedException(); } From 1ef077fa251d06ec3d451098bd551caae75c73d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 14 Nov 2021 20:40:42 +0300 Subject: [PATCH 12/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20hard=20delete?= =?UTF-8?q?=20operations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRepository.cs | 2 +- .../Repository.cs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/EasyRepository.EFCore.Entities/IRepository.cs b/src/EasyRepository.EFCore.Entities/IRepository.cs index abb218c..f740a9d 100644 --- a/src/EasyRepository.EFCore.Entities/IRepository.cs +++ b/src/EasyRepository.EFCore.Entities/IRepository.cs @@ -183,7 +183,7 @@ public interface IRepository /// /// Returns /// - Task HardDeleteAsync(object id, CancellationToken cancellationToken = default); + Task HardDeleteAsync(object id, CancellationToken cancellationToken = default) where TEntity : class, new(); /// diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 0a38d63..ca7736a 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -2,6 +2,7 @@ using AutoFilterer.Types; using EasyRepository.EFCore.Abstractions; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; using System; @@ -190,19 +191,24 @@ public void HardDelete(TPrimaryKey id) where TEntity : Eas await context.SaveChangesAsync(cancellationToken); } - public Task HardDeleteAsync(object id, CancellationToken cancellationToken = default) + public async Task HardDeleteAsync(object id, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id)); + context.Set().Remove(entity); + await context.SaveChangesAsync(cancellationToken); } - public Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public async Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + context.Set().Remove(entity); + await context.SaveChangesAsync(cancellationToken); } - public Task HardDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public async Task HardDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id)); + context.Set().Remove(entity); + await context.SaveChangesAsync(cancellationToken); } public TEntity Replace(TEntity entity) where TEntity : class, new() From e36eafcd64ac6b62e25fa50a137555bd2aa5c5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 14 Nov 2021 20:51:10 +0300 Subject: [PATCH 13/49] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Implement=20configur?= =?UTF-8?q?e=20await=20tasks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index ca7736a..56b2f9c 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -159,61 +159,61 @@ private Expression> GenerateExpression(object id) return expression; } - public void HardDelete(TEntity entity) where TEntity : class, new() + public virtual void HardDelete(TEntity entity) where TEntity : class, new() { context.Set().Remove(entity); context.SaveChanges(); } - public void HardDelete(object id) where TEntity : class, new() + public virtual void HardDelete(object id) where TEntity : class, new() { var entity = context.Set().Find(id); context.Set().Remove(entity); context.SaveChanges(); } - public void HardDelete(TEntity entity) where TEntity : EasyBaseEntity + public virtual void HardDelete(TEntity entity) where TEntity : EasyBaseEntity { context.Set().Remove(entity); context.SaveChanges(); } - public void HardDelete(TPrimaryKey id) where TEntity : EasyBaseEntity + public virtual void HardDelete(TPrimaryKey id) where TEntity : EasyBaseEntity { var entity = context.Set().FirstOrDefault(GenerateExpression(id)); context.Set().Remove(entity); context.SaveChanges(); } - public async Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() { context.Set().Remove(entity); - await context.SaveChangesAsync(cancellationToken); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } - public async Task HardDeleteAsync(object id, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task HardDeleteAsync(object id, CancellationToken cancellationToken = default) where TEntity : class, new() { - var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id)); + var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id)).ConfigureAwait(false); context.Set().Remove(entity); - await context.SaveChangesAsync(cancellationToken); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } - public async Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public virtual async Task HardDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { context.Set().Remove(entity); - await context.SaveChangesAsync(cancellationToken); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } - public async Task HardDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public virtual async Task HardDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id)); + var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id)).ConfigureAwait(false); context.Set().Remove(entity); await context.SaveChangesAsync(cancellationToken); } - public TEntity Replace(TEntity entity) where TEntity : class, new() + public virtual TEntity Replace(TEntity entity) where TEntity : class, new() { - throw new NotImplementedException(); + } public TEntity Replace(TEntity entity) where TEntity : EasyBaseEntity From cf16b6a65a3bc68f8024b55a9256e79a6d78adaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 14 Nov 2021 20:56:15 +0300 Subject: [PATCH 14/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20replace=20oper?= =?UTF-8?q?ations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository.cs | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 56b2f9c..859ed75 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -213,22 +213,32 @@ public virtual async Task HardDeleteAsync(TPrimaryKey id, public virtual TEntity Replace(TEntity entity) where TEntity : class, new() { - + context.Entry(entity).State = EntityState.Modified; + context.SaveChanges(); + return entity; } - public TEntity Replace(TEntity entity) where TEntity : EasyBaseEntity + public virtual TEntity Replace(TEntity entity) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entity.ModificationDate = DateTime.UtcNow; + context.Entry(entity).State = EntityState.Modified; + context.SaveChanges(); + return entity; } - public Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + context.Entry(entity).State = EntityState.Modified; + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entity; } - public Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public virtual async Task ReplaceAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entity.ModificationDate = DateTime.UtcNow; + context.Entry(entity).State = EntityState.Modified; + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entity; } public void SoftDelete(TEntity entity) where TEntity : EasyBaseEntity From 88773fbab8271a65ef323c1f067c4d14eda69e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 14 Nov 2021 21:06:55 +0300 Subject: [PATCH 15/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20soft=20delete?= =?UTF-8?q?=20operations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository.cs | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 859ed75..821756f 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -193,7 +193,7 @@ public virtual void HardDelete(TPrimaryKey id) where TEnti public virtual async Task HardDeleteAsync(object id, CancellationToken cancellationToken = default) where TEntity : class, new() { - var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id)).ConfigureAwait(false); + var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id), cancellationToken).ConfigureAwait(false); context.Set().Remove(entity); await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } @@ -206,7 +206,7 @@ public virtual async Task HardDeleteAsync(TEntity entity, public virtual async Task HardDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id)).ConfigureAwait(false); + var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id), cancellationToken).ConfigureAwait(false); context.Set().Remove(entity); await context.SaveChangesAsync(cancellationToken); } @@ -241,24 +241,34 @@ public virtual async Task ReplaceAsync(TEntity en return entity; } - public void SoftDelete(TEntity entity) where TEntity : EasyBaseEntity + public virtual void SoftDelete(TEntity entity) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entity.IsDeleted = true; + entity.DeletionDate = DateTime.UtcNow; + Replace(entity); } - public void SoftDelete(TPrimaryKey id) where TEntity : EasyBaseEntity + public virtual void SoftDelete(TPrimaryKey id) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + var entity = context.Set().FirstOrDefault(GenerateExpression(id)); + entity.IsDeleted = true; + entity.DeletionDate = DateTime.UtcNow; + Replace(entity); } - public Task SoftDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public virtual async Task SoftDeleteAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entity.IsDeleted = true; + entity.DeletionDate = DateTime.UtcNow; + await ReplaceAsync(entity, cancellationToken).ConfigureAwait(false); } - public Task SoftDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public virtual async Task SoftDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id), cancellationToken).ConfigureAwait(false);; + entity.IsDeleted = true; + entity.DeletionDate = DateTime.UtcNow; + await ReplaceAsync(entity, cancellationToken).ConfigureAwait(false); } public TEntity Update(TEntity entity) where TEntity : class, new() From 4ac8ce638c51ae43927ce77e06a89d5115921caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 14 Nov 2021 21:15:25 +0300 Subject: [PATCH 16/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20update=20opera?= =?UTF-8?q?tions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRepository.cs | 4 +- .../Repository.cs | 52 +++++++++++++------ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/EasyRepository.EFCore.Entities/IRepository.cs b/src/EasyRepository.EFCore.Entities/IRepository.cs index f740a9d..9e9321e 100644 --- a/src/EasyRepository.EFCore.Entities/IRepository.cs +++ b/src/EasyRepository.EFCore.Entities/IRepository.cs @@ -427,13 +427,13 @@ public interface IRepository /// /// Type of Primary Key /// - /// + /// /// The entites to be updated /// /// /// Returns /// - Task> UpdateRangeAsync(IEnumerable entites, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity; + Task> UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity; /// /// This method takes performs replace operation. In additional returns diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 821756f..126be8a 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -271,44 +271,64 @@ public virtual async Task SoftDeleteAsync(TPrimaryKey id, await ReplaceAsync(entity, cancellationToken).ConfigureAwait(false); } - public TEntity Update(TEntity entity) where TEntity : class, new() + public virtual TEntity Update(TEntity entity) where TEntity : class, new() { - throw new NotImplementedException(); + context.Set().Update(entity); + context.SaveChanges(); + return entity; } - public TEntity Update(TEntity entity) where TEntity : EasyBaseEntity + public virtual TEntity Update(TEntity entity) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entity.ModificationDate = DateTime.UtcNow; + context.Set().Update(entity); + context.SaveChanges(); + return entity; } - public Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + context.Set().Update(entity); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entity; } - public Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public virtual async Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entity.ModificationDate = DateTime.UtcNow; + context.Set().Update(entity); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entity; } - public IEnumerable UpdateRange(IEnumerable entities) where TEntity : class, new() + public virtual IEnumerable UpdateRange(IEnumerable entities) where TEntity : class, new() { - throw new NotImplementedException(); + context.Set().UpdateRange(entities); + context.SaveChanges(); + return entities; } - public IEnumerable UpdateRange(IEnumerable entities) where TEntity : EasyBaseEntity + public virtual IEnumerable UpdateRange(IEnumerable entities) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entities.ToList().ForEach(a => a.ModificationDate = DateTime.UtcNow); + context.Set().UpdateRange(entities); + context.SaveChanges(); + return entities; } - public Task> UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task> UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + context.Set().UpdateRange(entities); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entities; } - public Task> UpdateRangeAsync(IEnumerable entites, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity + public virtual async Task> UpdateRangeAsync(IEnumerable entities, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - throw new NotImplementedException(); + entities.ToList().ForEach(a => a.ModificationDate = DateTime.UtcNow); + context.Set().UpdateRange(entities); + await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + return entities; } public IQueryable GetQueryable() where TEntity : class, new() From f67c68ec78e6436e60d9e08293b3dfeae8c6c1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 14 Nov 2021 21:17:16 +0300 Subject: [PATCH 17/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20get=20Queryabl?= =?UTF-8?q?e=20operations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/EasyRepository.EFCore.Generic/Repository.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 126be8a..9dd4a51 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -331,14 +331,14 @@ public virtual async Task> UpdateRangeAsync GetQueryable() where TEntity : class, new() + public virtual IQueryable GetQueryable() where TEntity : class, new() { - throw new NotImplementedException(); + return context.Set().AsQueryable(); } - public IQueryable GetQueryable(Expression> filter) where TEntity : class, new() + public virtual IQueryable GetQueryable(Expression> filter) where TEntity : class, new() { - throw new NotImplementedException(); + return context.Set().Where(filter); } public List GetMultiple(bool asNoTracking) where TEntity : class, new() From cdd61bc246e64cf2ed78e7fb1925abdd2844c31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sun, 14 Nov 2021 21:45:13 +0300 Subject: [PATCH 18/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20get=20multiple?= =?UTF-8?q?=20operations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository.cs | 122 +++++++++++------- 1 file changed, 76 insertions(+), 46 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 9dd4a51..86d442d 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -245,7 +245,7 @@ public virtual void SoftDelete(TEntity entity) where TEnti { entity.IsDeleted = true; entity.DeletionDate = DateTime.UtcNow; - Replace(entity); + Replace(entity); } public virtual void SoftDelete(TPrimaryKey id) where TEntity : EasyBaseEntity @@ -265,7 +265,7 @@ public virtual async Task SoftDeleteAsync(TEntity entity, public virtual async Task SoftDeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default) where TEntity : EasyBaseEntity { - var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id), cancellationToken).ConfigureAwait(false);; + var entity = await context.Set().FirstOrDefaultAsync(GenerateExpression(id), cancellationToken).ConfigureAwait(false); ; entity.IsDeleted = true; entity.DeletionDate = DateTime.UtcNow; await ReplaceAsync(entity, cancellationToken).ConfigureAwait(false); @@ -341,130 +341,160 @@ public virtual async Task> UpdateRangeAsync().Where(filter); } - public List GetMultiple(bool asNoTracking) where TEntity : class, new() + private IQueryable FindQueryable(bool asNoTracking) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = GetQueryable(); + if (asNoTracking) + { + queryable = queryable.AsNoTracking(); + } + return queryable; } - public Task> GetMultipleAsync(bool asNoTracking, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual List GetMultiple(bool asNoTracking) where TEntity : class, new() { - throw new NotImplementedException(); + return FindQueryable(asNoTracking).ToList(); } - public List GetMultiple(bool asNoTracking, Expression> projectExpression) where TEntity : class, new() + public virtual async Task> GetMultipleAsync(bool asNoTracking, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + return await FindQueryable(asNoTracking).ToListAsync(cancellationToken).ConfigureAwait(false); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual List GetMultiple(bool asNoTracking, Expression> projectExpression) where TEntity : class, new() { - throw new NotImplementedException(); + return FindQueryable(asNoTracking).Select(projectExpression).ToList(); } - public List GetMultiple(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() + public virtual async Task> GetMultipleAsync(bool asNoTracking, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + return await FindQueryable(asNoTracking).Select(projectExpression).ToListAsync(cancellationToken).ConfigureAwait(false); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual List GetMultiple(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() { - throw new NotImplementedException(); + return FindQueryable(asNoTracking).Where(whereExpression).ToList(); } - public List GetMultiple(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() + public virtual async Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + return await FindQueryable(asNoTracking).Where(whereExpression).ToListAsync(cancellationToken).ConfigureAwait(false); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual List GetMultiple(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() { - throw new NotImplementedException(); + return FindQueryable(asNoTracking).Where(whereExpression).Select(projectExpression).ToList(); } - public List GetMultiple(bool asNoTracking, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() + public virtual async Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + return await FindQueryable(asNoTracking).Where(whereExpression).Select(projectExpression).ToListAsync(cancellationToken).ConfigureAwait(false); } - public Task> GetMultipleAsync(bool asNoTracking, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual List GetMultiple(bool asNoTracking, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking); + queryable = includeExpression(queryable); + return queryable.ToList(); } - public List GetMultiple(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() + public virtual async Task> GetMultipleAsync(bool asNoTracking, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking); + queryable = includeExpression(queryable); + return await queryable.ToListAsync(cancellationToken).ConfigureAwait(false); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual List GetMultiple(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + queryable = includeExpression(queryable); + return queryable.ToList(); } - public List GetMultiple(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, Expression> projectExpression) where TEntity : class, new() + public virtual async Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + queryable = includeExpression(queryable); + return await queryable.ToListAsync(cancellationToken).ConfigureAwait(false); } - public Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual List GetMultiple(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, Expression> projectExpression) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + queryable = includeExpression(queryable); + return queryable.Select(projectExpression).ToList(); } - public List GetMultiple(bool asNoTracking, TFilter filter) + public virtual async Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + { + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + queryable = includeExpression(queryable); + return await queryable.Select(projectExpression).ToListAsync(cancellationToken).ConfigureAwait(false); + } + + public virtual List GetMultiple(bool asNoTracking, TFilter filter) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + return FindQueryable(asNoTracking).ApplyFilter(filter).ToList(); } - public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) + public virtual async Task> GetMultipleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + return await FindQueryable(asNoTracking).ApplyFilter(filter).ToListAsync(cancellationToken).ConfigureAwait(false); } - public List GetMultiple(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression) + public virtual List GetMultiple(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + queryable = includeExpression(queryable); + return queryable.ToList(); } - public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) + public virtual async Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + queryable = includeExpression(queryable); + return await queryable.ToListAsync(cancellationToken).ConfigureAwait(false); } - public List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression) + public virtual List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + return FindQueryable(asNoTracking).ApplyFilter(filter).Select(projectExpression).ToList(); } - public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) + public virtual async Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + return await FindQueryable(asNoTracking).ApplyFilter(filter).Select(projectExpression).ToListAsync(cancellationToken).ConfigureAwait(false); } - public List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) + public virtual List GetMultiple(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + queryable = includeExpression(queryable); + return queryable.Select(projectExpression).ToList(); } - public Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) + public virtual async Task> GetMultipleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + queryable = includeExpression(queryable); + return await queryable.Select(projectExpression).ToListAsync(cancellationToken).ConfigureAwait(false); } public TEntity GetSingle(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() From e5b3161f846c502ab0312d7ee52941d3798943cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Thu, 25 Nov 2021 21:05:51 +0300 Subject: [PATCH 19/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20Get=20Single?= =?UTF-8?q?=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository.cs | 86 ++++++++++++------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 86d442d..6aeacf0 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -497,100 +497,122 @@ public virtual async Task> GetMultipleAsync(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() + public virtual TEntity GetSingle(bool asNoTracking, Expression> whereExpression) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + return queryable.FirstOrDefault(); } - public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + return await queryable.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } - public TEntity GetSingle(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() + public virtual TEntity GetSingle(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + queryable = includeExpression(queryable); + return queryable.FirstOrDefault(); } - public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public async virtual Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + queryable = includeExpression(queryable); + return await queryable.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } - public TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() + public virtual TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression) where TEntity : class, new() { - throw new NotImplementedException(); + return FindQueryable(asNoTracking).Where(whereExpression).Select(projectExpression).FirstOrDefault(); } - public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + return await FindQueryable(asNoTracking).Where(whereExpression).Select(projectExpression).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } - public TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() + public virtual TProjected GetSingle(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + queryable = includeExpression(queryable); + return queryable.Select(projectExpression).FirstOrDefault(); } - public Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task GetSingleAsync(bool asNoTracking, Expression> whereExpression, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(whereExpression); + queryable = includeExpression(queryable); + return await queryable.Select(projectExpression).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } - public TEntity GetSingle(bool asNoTracking, TFilter filter) + public virtual TEntity GetSingle(bool asNoTracking, TFilter filter) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + return queryable.FirstOrDefault(); } - public Task GetSingleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) + public virtual async Task GetSingleAsync(bool asNoTracking, TFilter filter, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + return await queryable.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } - public TEntity GetSingle(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression) + public virtual TEntity GetSingle(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + queryable = includeExpression(queryable); + return queryable.FirstOrDefault(); } - public Task GetSingleAsync(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) + public virtual async Task GetSingleAsync(bool asNoTracking, TFilter filter, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + queryable = includeExpression(queryable); + return await queryable.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } - public TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression) + public virtual TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + return queryable.Select(projectExpression).FirstOrDefault(); } - public Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) + public virtual async Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + return await queryable.Select(projectExpression).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } - public TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) + public virtual TProjected GetSingle(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + queryable = includeExpression(queryable); + return queryable.Select(projectExpression).FirstOrDefault(); } - public Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) + public virtual async Task GetSingleAsync(bool asNoTracking, TFilter filter, Expression> projectExpression, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() where TFilter : FilterBase { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).ApplyFilter(filter); + queryable = includeExpression(queryable); + return await queryable.Select(projectExpression).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } public TEntity GetById(bool asNoTracking, object id) where TEntity : class, new() From 00b4797b0fb7608faf5f2d17a1e67cf09ea04a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:26:28 +0300 Subject: [PATCH 20/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20Get=20By=20Id?= =?UTF-8?q?=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IRepository.cs | 2 +- .../Repository.cs | 45 +++++++++++-------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/EasyRepository.EFCore.Entities/IRepository.cs b/src/EasyRepository.EFCore.Entities/IRepository.cs index 9e9321e..dfefd7a 100644 --- a/src/EasyRepository.EFCore.Entities/IRepository.cs +++ b/src/EasyRepository.EFCore.Entities/IRepository.cs @@ -1432,7 +1432,7 @@ public interface IRepository /// /// Returns /// - TEntity GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); + Task GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new(); /// diff --git a/src/EasyRepository.EFCore.Generic/Repository.cs b/src/EasyRepository.EFCore.Generic/Repository.cs index 6aeacf0..8ca7289 100644 --- a/src/EasyRepository.EFCore.Generic/Repository.cs +++ b/src/EasyRepository.EFCore.Generic/Repository.cs @@ -2,15 +2,12 @@ using AutoFilterer.Types; using EasyRepository.EFCore.Abstractions; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Query; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Linq.Expressions; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -615,44 +612,54 @@ public virtual async Task GetSingleAsync(bool asNoTracking, object id) where TEntity : class, new() + public virtual TEntity GetById(bool asNoTracking, object id) where TEntity : class, new() { - throw new NotImplementedException(); + return context.Set().FirstOrDefault(GenerateExpression(id)); } - public Task GetByIdAsync(bool asNoTracking, object id, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task GetByIdAsync(bool asNoTracking, object id, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + return await FindQueryable(asNoTracking).FirstOrDefaultAsync(GenerateExpression(id), cancellationToken).ConfigureAwait(false); } - public TEntity GetById(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() + public virtual TEntity GetById(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(GenerateExpression(id)); + queryable = includeExpression(queryable); + return queryable.FirstOrDefault(); } - public TEntity GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(GenerateExpression(id)); + queryable = includeExpression(queryable); + return await queryable.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } - public TProjected GetById(bool asNoTracking, object id, Expression> projectExpression) where TEntity : class, new() + public virtual TProjected GetById(bool asNoTracking, object id, Expression> projectExpression) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(GenerateExpression(id)); + return queryable.Select(projectExpression).FirstOrDefault(); } - public Task GetByIdAsync(bool asNoTracking, object id, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task GetByIdAsync(bool asNoTracking, object id, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(GenerateExpression(id)); + return await queryable.Select(projectExpression).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } - public TProjected GetById(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, Expression> projectExpression) where TEntity : class, new() + public virtual TProjected GetById(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, Expression> projectExpression) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(GenerateExpression(id)); + queryable = includeExpression(queryable); + return queryable.Select(projectExpression).FirstOrDefault(); } - public Task GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() + public virtual async Task GetByIdAsync(bool asNoTracking, object id, Func, IIncludableQueryable> includeExpression, Expression> projectExpression, CancellationToken cancellationToken = default) where TEntity : class, new() { - throw new NotImplementedException(); + var queryable = FindQueryable(asNoTracking).Where(GenerateExpression(id)); + queryable = includeExpression(queryable); + return await queryable.Select(projectExpression).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); } } } From 46ca13604c35dfb38efd9336d0af2a96a9f9d2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:33:02 +0300 Subject: [PATCH 21/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20service=20coll?= =?UTF-8?q?ection=20extensions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/EasyRepository.EFCore.Generic/Startup.cs | 40 ++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/EasyRepository.EFCore.Generic/Startup.cs diff --git a/src/EasyRepository.EFCore.Generic/Startup.cs b/src/EasyRepository.EFCore.Generic/Startup.cs new file mode 100644 index 0000000..9e7d06d --- /dev/null +++ b/src/EasyRepository.EFCore.Generic/Startup.cs @@ -0,0 +1,40 @@ +using EasyRepository.EFCore.Abstractions; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; + +namespace EasyRepository.EFCore.Generic +{ + /// + /// This class includes Service Collection extensions + /// + public static class Startup + { + /// + /// This method takes service lifetime and database context. In additional this method performs apply easy repository library for own db context + /// + /// + /// database context. + /// + /// + /// Service collection + /// + /// + /// Service LifeTime + /// + /// + /// + /// + public static IServiceCollection ApplyEasyRepository(this IServiceCollection services, ServiceLifetime serviceLifetime = ServiceLifetime.Transient) where TDbContext : DbContext + { + services.Add(new ServiceDescriptor( + typeof(IRepository), + serviceProvider => + { + TDbContext dbContext = ActivatorUtilities.CreateInstance(serviceProvider); + return new Repository(dbContext); + }, + serviceLifetime)); + return services; + } + } +} From 88ac62aa979dc4be282b8baa9aa0dd9e6136f2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:34:46 +0300 Subject: [PATCH 22/49] =?UTF-8?q?=F0=9F=8E=89=20TADA=20!!=20Begin=20EasyRe?= =?UTF-8?q?pository.Sample=20project?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasyRepository.EFCore.sln | 21 +++++++++- .../EasyRepository.Sample.csproj | 7 ++++ sample/EasyRepository.Sample/Program.cs | 26 ++++++++++++ .../Properties/launchSettings.json | 28 +++++++++++++ sample/EasyRepository.Sample/Startup.cs | 40 +++++++++++++++++++ .../appsettings.Development.json | 9 +++++ sample/EasyRepository.Sample/appsettings.json | 10 +++++ 7 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 sample/EasyRepository.Sample/EasyRepository.Sample.csproj create mode 100644 sample/EasyRepository.Sample/Program.cs create mode 100644 sample/EasyRepository.Sample/Properties/launchSettings.json create mode 100644 sample/EasyRepository.Sample/Startup.cs create mode 100644 sample/EasyRepository.Sample/appsettings.Development.json create mode 100644 sample/EasyRepository.Sample/appsettings.json diff --git a/EasyRepository.EFCore.sln b/EasyRepository.EFCore.sln index 23dbf97..9166381 100644 --- a/EasyRepository.EFCore.sln +++ b/EasyRepository.EFCore.sln @@ -5,9 +5,9 @@ VisualStudioVersion = 16.6.30114.105 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{6ECD69C4-213C-400A-8EFE-DB1B5E33DC29}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyRepository.EFCore.Abstractions", "src\EasyRepository.EFCore.Entities\EasyRepository.EFCore.Abstractions.csproj", "{9B909B96-23EC-48CE-A9A8-237F714896E9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyRepository.EFCore.Abstractions", "src\EasyRepository.EFCore.Entities\EasyRepository.EFCore.Abstractions.csproj", "{9B909B96-23EC-48CE-A9A8-237F714896E9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyRepository.EFCore.Generic", "src\EasyRepository.EFCore.Generic\EasyRepository.EFCore.Generic.csproj", "{730B0EE2-7048-4F0E-9DA0-7F0DDED22707}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyRepository.EFCore.Generic", "src\EasyRepository.EFCore.Generic\EasyRepository.EFCore.Generic.csproj", "{730B0EE2-7048-4F0E-9DA0-7F0DDED22707}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CB94A892-F59B-42D2-BE0D-31E0879CEEE7}" ProjectSection(SolutionItems) = preProject @@ -15,6 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{1670C5F3-D8A7-42DB-A377-5405F1B4BCE6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyRepository.Sample", "sample\EasyRepository.Sample\EasyRepository.Sample.csproj", "{84940E1B-6A42-4485-82DC-4EE105B637AA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +53,18 @@ Global {730B0EE2-7048-4F0E-9DA0-7F0DDED22707}.Release|x64.Build.0 = Release|Any CPU {730B0EE2-7048-4F0E-9DA0-7F0DDED22707}.Release|x86.ActiveCfg = Release|Any CPU {730B0EE2-7048-4F0E-9DA0-7F0DDED22707}.Release|x86.Build.0 = Release|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|x64.ActiveCfg = Debug|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|x64.Build.0 = Debug|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|x86.ActiveCfg = Debug|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Debug|x86.Build.0 = Debug|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|Any CPU.Build.0 = Release|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|x64.ActiveCfg = Release|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|x64.Build.0 = Release|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|x86.ActiveCfg = Release|Any CPU + {84940E1B-6A42-4485-82DC-4EE105B637AA}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -56,6 +72,7 @@ Global GlobalSection(NestedProjects) = preSolution {9B909B96-23EC-48CE-A9A8-237F714896E9} = {6ECD69C4-213C-400A-8EFE-DB1B5E33DC29} {730B0EE2-7048-4F0E-9DA0-7F0DDED22707} = {6ECD69C4-213C-400A-8EFE-DB1B5E33DC29} + {84940E1B-6A42-4485-82DC-4EE105B637AA} = {1670C5F3-D8A7-42DB-A377-5405F1B4BCE6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {82B432B5-EED3-42E9-AFEC-D899479E4CC3} diff --git a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj new file mode 100644 index 0000000..842a770 --- /dev/null +++ b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/sample/EasyRepository.Sample/Program.cs b/sample/EasyRepository.Sample/Program.cs new file mode 100644 index 0000000..0f353d9 --- /dev/null +++ b/sample/EasyRepository.Sample/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/sample/EasyRepository.Sample/Properties/launchSettings.json b/sample/EasyRepository.Sample/Properties/launchSettings.json new file mode 100644 index 0000000..ec2e8e8 --- /dev/null +++ b/sample/EasyRepository.Sample/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:55325", + "sslPort": 44383 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "EasyRepository.Sample": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/sample/EasyRepository.Sample/Startup.cs b/sample/EasyRepository.Sample/Startup.cs new file mode 100644 index 0000000..a36a5dc --- /dev/null +++ b/sample/EasyRepository.Sample/Startup.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample +{ + public class Startup + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapGet("/", async context => + { + await context.Response.WriteAsync("Hello World!"); + }); + }); + } + } +} diff --git a/sample/EasyRepository.Sample/appsettings.Development.json b/sample/EasyRepository.Sample/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/sample/EasyRepository.Sample/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/sample/EasyRepository.Sample/appsettings.json b/sample/EasyRepository.Sample/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/sample/EasyRepository.Sample/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} From d288114966f0c97c2be92090d21dbdd1ade986df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:35:24 +0300 Subject: [PATCH 23/49] =?UTF-8?q?=E2=9E=95=20Add=20EasyRepository.Generic?= =?UTF-8?q?=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/EasyRepository.Sample.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj index 842a770..836ced6 100644 --- a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj +++ b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj @@ -4,4 +4,8 @@ net5.0 + + + + From 9ba94d07f6f519e352921449cd941f54b47d0845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:37:17 +0300 Subject: [PATCH 24/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20sample=20db=20contex?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Context/SampleDbContext.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 sample/EasyRepository.Sample/Context/SampleDbContext.cs diff --git a/sample/EasyRepository.Sample/Context/SampleDbContext.cs b/sample/EasyRepository.Sample/Context/SampleDbContext.cs new file mode 100644 index 0000000..2b1d988 --- /dev/null +++ b/sample/EasyRepository.Sample/Context/SampleDbContext.cs @@ -0,0 +1,32 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample.Context +{ + /// + /// Sample Database Context + /// + public class SampleDbContext : DbContext + { + /// + /// Ctor + /// + /// + /// The options to be used by a Microsoft.EntityFrameworkCore.DbContext. You normally + /// override Microsoft.EntityFrameworkCore.DbContext.OnConfiguring(Microsoft.EntityFrameworkCore.DbContextOptionsBuilder) + /// or use a Microsoft.EntityFrameworkCore.DbContextOptionsBuilder to create instances + /// of this class and it is not designed to be directly constructed in your application + /// code. + /// + public SampleDbContext(DbContextOptions options) : base(options) + { + } + + protected SampleDbContext() + { + } + } +} From 81c1b722fd733c9b855e0ec164d91d7e1af8fc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:39:56 +0300 Subject: [PATCH 25/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20author=20entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/Entities/Author.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 sample/EasyRepository.Sample/Entities/Author.cs diff --git a/sample/EasyRepository.Sample/Entities/Author.cs b/sample/EasyRepository.Sample/Entities/Author.cs new file mode 100644 index 0000000..304a095 --- /dev/null +++ b/sample/EasyRepository.Sample/Entities/Author.cs @@ -0,0 +1,17 @@ +using EasyRepository.EFCore.Abstractions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample.Entities +{ + public class Author : EasyBaseEntity + { + public string Name { get; set; } + + public string Surname { get; set; } + + public virtual ICollection Books { get; set; } + } +} From 300e48da2d533dd0d4ae35886f188ac21eafac32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:40:06 +0300 Subject: [PATCH 26/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20book=20entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/Entities/Book.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 sample/EasyRepository.Sample/Entities/Book.cs diff --git a/sample/EasyRepository.Sample/Entities/Book.cs b/sample/EasyRepository.Sample/Entities/Book.cs new file mode 100644 index 0000000..e8d9087 --- /dev/null +++ b/sample/EasyRepository.Sample/Entities/Book.cs @@ -0,0 +1,17 @@ +using EasyRepository.EFCore.Abstractions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample.Entities +{ + public class Book : EasyBaseEntity + { + public string Title { get; set; } + + public int TotalPage { get; set; } + + public virtual Author Author { get; set; } + } +} From cbf41958befaeff52935e9e5e51eb5a2226cecf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:41:57 +0300 Subject: [PATCH 27/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20entities=20in=20db?= =?UTF-8?q?=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Context/SampleDbContext.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sample/EasyRepository.Sample/Context/SampleDbContext.cs b/sample/EasyRepository.Sample/Context/SampleDbContext.cs index 2b1d988..6e085c3 100644 --- a/sample/EasyRepository.Sample/Context/SampleDbContext.cs +++ b/sample/EasyRepository.Sample/Context/SampleDbContext.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using EasyRepository.Sample.Entities; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -28,5 +29,19 @@ public SampleDbContext(DbContextOptions options) : base(options) protected SampleDbContext() { } + + public virtual DbSet Authors { get; set;} + + public virtual DbSet Books { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + } } } From e77b2fcf964190f1d2e82b893221d5be3190835d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:48:17 +0300 Subject: [PATCH 28/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20Startup=20conf?= =?UTF-8?q?iguration=20for=20EasyRepository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/Startup.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sample/EasyRepository.Sample/Startup.cs b/sample/EasyRepository.Sample/Startup.cs index a36a5dc..06b69e2 100644 --- a/sample/EasyRepository.Sample/Startup.cs +++ b/sample/EasyRepository.Sample/Startup.cs @@ -1,3 +1,5 @@ +using EasyRepository.EFCore.Generic; +using EasyRepository.Sample.Context; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -16,6 +18,7 @@ public class Startup // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.ApplyEasyRepository(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. From 26d9b65e36ea5b0b029d99acf19b4543ad348714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:48:56 +0300 Subject: [PATCH 29/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20Add=20Controller=20W?= =?UTF-8?q?ith=20Wiews?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/Startup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/sample/EasyRepository.Sample/Startup.cs b/sample/EasyRepository.Sample/Startup.cs index 06b69e2..f925098 100644 --- a/sample/EasyRepository.Sample/Startup.cs +++ b/sample/EasyRepository.Sample/Startup.cs @@ -18,6 +18,7 @@ public class Startup // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.AddControllersWithViews(); services.ApplyEasyRepository(); } From a26599ee4bac89505027c01c312aad5965711fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:49:55 +0300 Subject: [PATCH 30/49] =?UTF-8?q?=F0=9F=99=88=20Update=20gitignore=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9491a2f..e08b42c 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,6 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +appsettings.*.json \ No newline at end of file From e041651cda7ebb6f1b53f26a9c27c6dac15ae69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:50:10 +0300 Subject: [PATCH 31/49] =?UTF-8?q?=F0=9F=94=A5=20Remove=20appsettings.Devel?= =?UTF-8?q?opment.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EasyRepository.EFCore.sln | 1 + .../EasyRepository.Sample/appsettings.Development.json | 9 --------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 sample/EasyRepository.Sample/appsettings.Development.json diff --git a/EasyRepository.EFCore.sln b/EasyRepository.EFCore.sln index 9166381..825e13e 100644 --- a/EasyRepository.EFCore.sln +++ b/EasyRepository.EFCore.sln @@ -11,6 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyRepository.EFCore.Gener EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CB94A892-F59B-42D2-BE0D-31E0879CEEE7}" ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore common.props = common.props README.md = README.md EndProjectSection diff --git a/sample/EasyRepository.Sample/appsettings.Development.json b/sample/EasyRepository.Sample/appsettings.Development.json deleted file mode 100644 index 8983e0f..0000000 --- a/sample/EasyRepository.Sample/appsettings.Development.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} From 646b5dc011dd41e828acd03b3b50af96e6c2546c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:51:34 +0300 Subject: [PATCH 32/49] =?UTF-8?q?=E2=9E=95=20Add=20Npgsql.EntityFrameworkC?= =?UTF-8?q?ore.PostgreSQL=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/EasyRepository.Sample.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj index 836ced6..ad4286c 100644 --- a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj +++ b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj @@ -4,6 +4,10 @@ net5.0 + + + + From 4592f3128ee3ef9225cf939771d9b845f8912679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:56:07 +0300 Subject: [PATCH 33/49] =?UTF-8?q?=F0=9F=94=A8=20Configure=20database=20con?= =?UTF-8?q?nection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/Startup.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sample/EasyRepository.Sample/Startup.cs b/sample/EasyRepository.Sample/Startup.cs index f925098..ac2635b 100644 --- a/sample/EasyRepository.Sample/Startup.cs +++ b/sample/EasyRepository.Sample/Startup.cs @@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; @@ -14,12 +16,23 @@ namespace EasyRepository.Sample { public class Startup { + public IConfiguration Configuration { get; } + + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.ApplyEasyRepository(); + + services.AddDbContext(options => + { + options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")); + }, ServiceLifetime.Transient); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. From 361cf3bca7083e09e491133a8f3ddc1b74c5778a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:56:51 +0300 Subject: [PATCH 34/49] =?UTF-8?q?=E2=9E=95=20Add=20Microsoft.EntityFramewo?= =?UTF-8?q?rkCore.Tools=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/EasyRepository.Sample.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj index ad4286c..d52a3c1 100644 --- a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj +++ b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj @@ -5,6 +5,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From 84faa7b4c6dde6e5988d5ac182d1d80d357bea69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 12:58:26 +0300 Subject: [PATCH 35/49] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Add=20initial=20m?= =?UTF-8?q?igration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20211126095757_Initial.Designer.cs | 103 ++++++++++++++++++ .../Migrations/20211126095757_Initial.cs | 66 +++++++++++ .../SampleDbContextModelSnapshot.cs | 101 +++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 sample/EasyRepository.Sample/Migrations/20211126095757_Initial.Designer.cs create mode 100644 sample/EasyRepository.Sample/Migrations/20211126095757_Initial.cs create mode 100644 sample/EasyRepository.Sample/Migrations/SampleDbContextModelSnapshot.cs diff --git a/sample/EasyRepository.Sample/Migrations/20211126095757_Initial.Designer.cs b/sample/EasyRepository.Sample/Migrations/20211126095757_Initial.Designer.cs new file mode 100644 index 0000000..a2e7a75 --- /dev/null +++ b/sample/EasyRepository.Sample/Migrations/20211126095757_Initial.Designer.cs @@ -0,0 +1,103 @@ +// +using System; +using EasyRepository.Sample.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace EasyRepository.Sample.Migrations +{ + [DbContext(typeof(SampleDbContext))] + [Migration("20211126095757_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.12") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("DeletionDate") + .HasColumnType("timestamp without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Surname") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AuthorId") + .HasColumnType("uuid"); + + b.Property("CreationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("DeletionDate") + .HasColumnType("timestamp without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("Title") + .HasColumnType("text"); + + b.Property("TotalPage") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Book", b => + { + b.HasOne("EasyRepository.Sample.Entities.Author", "Author") + .WithMany("Books") + .HasForeignKey("AuthorId"); + + b.Navigation("Author"); + }); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Author", b => + { + b.Navigation("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/sample/EasyRepository.Sample/Migrations/20211126095757_Initial.cs b/sample/EasyRepository.Sample/Migrations/20211126095757_Initial.cs new file mode 100644 index 0000000..1cba89d --- /dev/null +++ b/sample/EasyRepository.Sample/Migrations/20211126095757_Initial.cs @@ -0,0 +1,66 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace EasyRepository.Sample.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Authors", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "text", nullable: true), + Surname = table.Column(type: "text", nullable: true), + CreationDate = table.Column(type: "timestamp without time zone", nullable: false), + ModificationDate = table.Column(type: "timestamp without time zone", nullable: true), + DeletionDate = table.Column(type: "timestamp without time zone", nullable: true), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Authors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Books", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Title = table.Column(type: "text", nullable: true), + TotalPage = table.Column(type: "integer", nullable: false), + AuthorId = table.Column(type: "uuid", nullable: true), + CreationDate = table.Column(type: "timestamp without time zone", nullable: false), + ModificationDate = table.Column(type: "timestamp without time zone", nullable: true), + DeletionDate = table.Column(type: "timestamp without time zone", nullable: true), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Books", x => x.Id); + table.ForeignKey( + name: "FK_Books_Authors_AuthorId", + column: x => x.AuthorId, + principalTable: "Authors", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_Books_AuthorId", + table: "Books", + column: "AuthorId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Books"); + + migrationBuilder.DropTable( + name: "Authors"); + } + } +} diff --git a/sample/EasyRepository.Sample/Migrations/SampleDbContextModelSnapshot.cs b/sample/EasyRepository.Sample/Migrations/SampleDbContextModelSnapshot.cs new file mode 100644 index 0000000..e8eae5c --- /dev/null +++ b/sample/EasyRepository.Sample/Migrations/SampleDbContextModelSnapshot.cs @@ -0,0 +1,101 @@ +// +using System; +using EasyRepository.Sample.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace EasyRepository.Sample.Migrations +{ + [DbContext(typeof(SampleDbContext))] + partial class SampleDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.12") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("DeletionDate") + .HasColumnType("timestamp without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Surname") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AuthorId") + .HasColumnType("uuid"); + + b.Property("CreationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("DeletionDate") + .HasColumnType("timestamp without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("Title") + .HasColumnType("text"); + + b.Property("TotalPage") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Book", b => + { + b.HasOne("EasyRepository.Sample.Entities.Author", "Author") + .WithMany("Books") + .HasForeignKey("AuthorId"); + + b.Navigation("Author"); + }); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Author", b => + { + b.Navigation("Books"); + }); +#pragma warning restore 612, 618 + } + } +} From a57c090589e8135c1737454a21a6948d05454a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 13:00:27 +0300 Subject: [PATCH 36/49] =?UTF-8?q?=E2=9E=95=20Add=20Swashbuckle.AspNetCore?= =?UTF-8?q?=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EasyRepository.Sample.csproj | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj index d52a3c1..b01c88d 100644 --- a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj +++ b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj @@ -1,19 +1,20 @@ - + - - net5.0 - + + net5.0 + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - - + + + From 1517d7d11fe5fe95d3b1d8f5a019bef9f7e46011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 13:01:39 +0300 Subject: [PATCH 37/49] =?UTF-8?q?=E2=9E=95=20Add=20AspNetCore.MarkdownDocu?= =?UTF-8?q?menting=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/EasyRepository.Sample.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj index b01c88d..a27c536 100644 --- a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj +++ b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj @@ -5,6 +5,7 @@ + all From 38cad556a78d5a566928f67f45fb9ad1220c6f8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 13:02:16 +0300 Subject: [PATCH 38/49] =?UTF-8?q?=E2=9E=95=20Add=20AutoFilterer.Swagger=20?= =?UTF-8?q?dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/EasyRepository.Sample.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj index a27c536..d2d4266 100644 --- a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj +++ b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj @@ -5,6 +5,7 @@ + From f46a9e6d7878a64e4ec6da4465c1b4591d70d623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Fri, 26 Nov 2021 13:05:39 +0300 Subject: [PATCH 39/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20swagger=20for?= =?UTF-8?q?=20sample=20project?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EasyRepository.Sample.csproj | 4 +- sample/EasyRepository.Sample/Startup.cs | 40 +++++++++++++++++++ sample/EasyRepository.Sample/appsettings.json | 30 +++++++++++++- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj index d2d4266..5efd121 100644 --- a/sample/EasyRepository.Sample/EasyRepository.Sample.csproj +++ b/sample/EasyRepository.Sample/EasyRepository.Sample.csproj @@ -3,7 +3,9 @@ net5.0 - + + bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + diff --git a/sample/EasyRepository.Sample/Startup.cs b/sample/EasyRepository.Sample/Startup.cs index ac2635b..b972147 100644 --- a/sample/EasyRepository.Sample/Startup.cs +++ b/sample/EasyRepository.Sample/Startup.cs @@ -1,5 +1,7 @@ +using AutoFilterer.Swagger; using EasyRepository.EFCore.Generic; using EasyRepository.Sample.Context; +using MarkdownDocumenting.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -9,7 +11,9 @@ using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Reflection; using System.Threading.Tasks; namespace EasyRepository.Sample @@ -33,6 +37,31 @@ public void ConfigureServices(IServiceCollection services) { options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")); }, ServiceLifetime.Transient); + + services.AddSwaggerGen(options => + { + options.SwaggerDoc("EasyRepository", new Microsoft.OpenApi.Models.OpenApiInfo() + { + Title = "Easy Repository", + Version = "1.0.0", + Description = "This repo, provides implement generic repository pattern on ef core", + Contact = new Microsoft.OpenApi.Models.OpenApiContact() + { + Email = "furkan.dvlp@gmail.com", + Url = new Uri("https://github.com/furkandeveloper/EasyRepository.EFCore") + } + }); + options.UseAutoFiltererParameters(); + var docFile = $"{Assembly.GetEntryAssembly().GetName().Name}.xml"; + var filePath = Path.Combine(AppContext.BaseDirectory, docFile); + + if (File.Exists((filePath))) + { + options.IncludeXmlComments(filePath); + } + options.DescribeAllParametersInCamelCase(); + }); + services.AddDocumentation(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -44,7 +73,18 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) } app.UseRouting(); + app.UseSwagger(); + app.UseSwaggerUI(options => + { + options.EnableDeepLinking(); + options.ShowExtensions(); + options.DisplayRequestDuration(); + options.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None); + options.RoutePrefix = "api-docs"; + options.SwaggerEndpoint("/swagger/EasyProfiler/swagger.json", "EasyProfilerSwagger"); + }); + app.UseDocumentation(opts => this.Configuration.Bind("DocumentationOptions", opts)); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => diff --git a/sample/EasyRepository.Sample/appsettings.json b/sample/EasyRepository.Sample/appsettings.json index d9d9a9b..5ea7a98 100644 --- a/sample/EasyRepository.Sample/appsettings.json +++ b/sample/EasyRepository.Sample/appsettings.json @@ -6,5 +6,33 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "DocumentationOptions": { + "HighlightJsStyle": "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.8/styles/zenburn.min.css", + "GetMdlStyle": "https://code.getmdl.io/1.3.0/material.indigo-pink.min.css", + "RoutePrefix": "", + "RootPathHandling": "Redirect", + "FooterMetaDatas": [ + { + "Display": "Swagger", + "Url": "/api-docs/index.html" + }, + { + "Display": "Repository", + "Url": "https://github.com/furkandeveloper/EasyRepositor", + "OpenInNewWindow": true + }, + { + "Display": "Furkan Güngör || Code Engineer", + "Url": "https://furkangungor.krawl.me/", + "OpenInNewWindow": true + } + ], + "CustomLinks": [ + { + "Display": "Swagger Swashbuckle", + "Url": "/api-docs" + } + ] + } } From 77976e9940e34745f846ad85624a8376d8a987a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:31:50 +0300 Subject: [PATCH 40/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20relation=20on?= =?UTF-8?q?=20sample=20database=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Context/SampleDbContext.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sample/EasyRepository.Sample/Context/SampleDbContext.cs b/sample/EasyRepository.Sample/Context/SampleDbContext.cs index 6e085c3..9154f1d 100644 --- a/sample/EasyRepository.Sample/Context/SampleDbContext.cs +++ b/sample/EasyRepository.Sample/Context/SampleDbContext.cs @@ -37,6 +37,21 @@ protected SampleDbContext() protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); + modelBuilder.Entity(entity => + { + entity + .HasMany(m => m.Books) + .WithOne(o => o.Author) + .HasForeignKey(fk => fk.AuthorId); + }); + + modelBuilder.Entity(entity => + { + entity + .HasOne(o => o.Author) + .WithMany(m => m.Books) + .HasForeignKey(fk => fk.AuthorId); + }); } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) From 703b702533d4a1c46072545b34dc6861ab7dc850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:32:03 +0300 Subject: [PATCH 41/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20author=20contr?= =?UTF-8?q?oller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AuthorController.cs | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 sample/EasyRepository.Sample/Controllers/AuthorController.cs diff --git a/sample/EasyRepository.Sample/Controllers/AuthorController.cs b/sample/EasyRepository.Sample/Controllers/AuthorController.cs new file mode 100644 index 0000000..361ebd3 --- /dev/null +++ b/sample/EasyRepository.Sample/Controllers/AuthorController.cs @@ -0,0 +1,123 @@ +using EasyRepository.EFCore.Abstractions; +using EasyRepository.Sample.Dtos.Request; +using EasyRepository.Sample.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Query; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample.Controllers +{ + [ApiController] + [Route("[controller]")] + public class AuthorController : ControllerBase + { + private readonly IRepository repository; + + public AuthorController(IRepository repository) + { + this.repository = repository; + } + + [HttpPost] + public async Task AddAuthorAsync([FromBody] AuthorRequestDto dto) + { + var entity = await repository.AddAsync(new Author + { + Name = dto.Name, + Surname = dto.Surname + }, default); + + return Ok(entity); + } + + [HttpPost("range")] + public async Task AddAuthorAsync([FromBody] List dto) + { + var entity = await repository.AddRangeAsync(dto.Select(s => new Author + { + Name = s.Name, + Surname = s.Surname + }).ToList(), default); + + return Ok(entity); + } + + [HttpPut("{id}")] + public async Task UpdateAuthorAsync([FromRoute] Guid id, [FromBody] AuthorRequestDto dto) + { + var entity = await repository.GetByIdAsync(true, id); + entity.Name = dto.Name; + entity.Surname = dto.Surname; + var result = await repository.UpdateAsync(entity); + return Ok(result); + } + + [HttpDelete("{id}/hard")] + public async Task HardDeleteAsync([FromRoute] Guid id) + { + var entity = await repository.GetByIdAsync(true, id); + await repository.HardDeleteAsync(entity); + return NoContent(); + } + + [HttpDelete("{id}/soft")] + public async Task SoftDeleteAsync([FromRoute] Guid id) + { + var entity = await repository.GetByIdAsync(true, id); + await repository.SoftDeleteAsync(entity); + return NoContent(); + } + + [HttpGet("{id}")] + public async Task GetByIdAsync([FromRoute] Guid id) + { + var entity = await repository.GetByIdAsync(true, id); + return Ok(entity); + } + + [HttpGet("multiple")] + public async Task GetMultipleAsync() + { + var entities = await repository.GetMultipleAsync(false); + return Ok(entities); + } + + [HttpGet("selectable-multiple")] + public async Task GetSelectableMultipleAsync() + { + var entities = await repository.GetMultipleAsync(false, select => new + { + SelectName = select.Name, + SelectDate = select.CreationDate + }); + return Ok(entities); + } + + [HttpGet("filterable-multiple")] + public async Task GetFilterableMultipleAsync([FromQuery] AuthorFilterDto dto) + { + var entities = await repository.GetMultipleAsync(false, dto, select => new + { + SelectName = select.Name, + SelectDate = select.CreationDate + }); + return Ok(entities); + } + + [HttpGet("includable-filterable-selectable-multiple")] + public async Task GetIncludeableFilterableMultipleAsync([FromQuery] AuthorFilterDto dto) + { + Func, IIncludableQueryable> include = a => a.Include(i => i.Books); + var entities = await repository.GetMultipleAsync(false, dto, select => new + { + SelectName = select.Name, + SelectDate = select.CreationDate + }, include); + return Ok(entities); + } + } +} From 988f290c3f7fa1591b879583da5c72717a3de0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:32:14 +0300 Subject: [PATCH 42/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20Book=20Control?= =?UTF-8?q?ler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BookController.cs | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 sample/EasyRepository.Sample/Controllers/BookController.cs diff --git a/sample/EasyRepository.Sample/Controllers/BookController.cs b/sample/EasyRepository.Sample/Controllers/BookController.cs new file mode 100644 index 0000000..c27d722 --- /dev/null +++ b/sample/EasyRepository.Sample/Controllers/BookController.cs @@ -0,0 +1,127 @@ +using EasyRepository.EFCore.Abstractions; +using EasyRepository.Sample.Dtos.Request; +using EasyRepository.Sample.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Query; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample.Controllers +{ + [ApiController] + [Route("[controller]")] + public class BookController : ControllerBase + { + private readonly IRepository repository; + + public BookController(IRepository repository) + { + this.repository = repository; + } + + [HttpPost("authors/{authorId}")] + public async Task AddBookAsync([FromRoute] Guid authorId,[FromBody] BookRequestDto dto) + { + var entity = await repository.AddAsync(new Book + { + Title = dto.Title, + TotalPage = dto.TotalPage, + AuthorId = authorId + }, default); + + return Ok(entity); + } + + [HttpPost("authors/{authorId}/range")] + public async Task AddBookAsync([FromRoute] Guid authorId, [FromBody] List dto) + { + var entity = await repository.AddRangeAsync(dto.Select(s => new Book + { + Title = s.Title, + TotalPage = s.TotalPage, + AuthorId = authorId + }).ToList(), default); + + return Ok(entity); + } + + [HttpPut("{id}/authors/{authorId}")] + public async Task UpdateAuthorAsync([FromRoute] Guid id,[FromRoute] Guid authorId, [FromBody] BookRequestDto dto) + { + var entity = await repository.GetByIdAsync(true, id); + entity.Title = dto.Title; + entity.TotalPage = dto.TotalPage; + entity.AuthorId = authorId; + var result = await repository.UpdateAsync(entity); + return Ok(result); + } + + [HttpDelete("{id}/hard")] + public async Task HardDeleteAsync([FromRoute] Guid id) + { + var entity = await repository.GetByIdAsync(true, id); + await repository.HardDeleteAsync(entity); + return NoContent(); + } + + [HttpDelete("{id}/soft")] + public async Task SoftDeleteAsync([FromRoute] Guid id) + { + var entity = await repository.GetByIdAsync(true, id); + await repository.SoftDeleteAsync(entity); + return NoContent(); + } + + [HttpGet("{id}")] + public async Task GetByIdAsync([FromRoute] Guid id) + { + var entity = await repository.GetByIdAsync(true, id); + return Ok(entity); + } + + [HttpGet("multiple")] + public async Task GetMultipleAsync() + { + var entities = await repository.GetMultipleAsync(false); + return Ok(entities); + } + + [HttpGet("selectable-multiple")] + public async Task GetSelectableMultipleAsync() + { + var entities = await repository.GetMultipleAsync(false, select => new + { + SelectTitle = select.Title, + SelectTotalPage = select.TotalPage + }); + return Ok(entities); + } + + [HttpGet("filterable-multiple")] + public async Task GetFilterableMultipleAsync([FromQuery] BookFilterDto dto) + { + var entities = await repository.GetMultipleAsync(false, dto, select => new + { + SelectTitle = select.Title, + SelectTotalPage = select.TotalPage + }); + return Ok(entities); + } + + [HttpGet("includable-filterable-selectable-multiple")] + public async Task GetIncludeableFilterableMultipleAsync([FromQuery] BookFilterDto dto) + { + Func, IIncludableQueryable> include = a => a.Include(i => i.Author); + var entities = await repository.GetMultipleAsync(false, dto, select => new + { + SelectName = select.Title, + SelectDate = select.CreationDate, + Author = select.Author.Name + }, include); + return Ok(entities); + } + } +} From b068a4463be5ebc9f6941f3aa90523823ef5f074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:32:51 +0300 Subject: [PATCH 43/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20Author=20Filter=20Da?= =?UTF-8?q?ta=20Transfer=20Object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Request/AuthorFilterDto.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sample/EasyRepository.Sample/Dtos/Request/AuthorFilterDto.cs diff --git a/sample/EasyRepository.Sample/Dtos/Request/AuthorFilterDto.cs b/sample/EasyRepository.Sample/Dtos/Request/AuthorFilterDto.cs new file mode 100644 index 0000000..8e44b18 --- /dev/null +++ b/sample/EasyRepository.Sample/Dtos/Request/AuthorFilterDto.cs @@ -0,0 +1,30 @@ +using AutoFilterer.Attributes; +using AutoFilterer.Types; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample.Dtos.Request +{ + [PossibleSortings("Name", "Surname","CreationDate", "ModificationDate", "DeletionDate")] + public class AuthorFilterDto : PaginationFilterBase + { + public AuthorFilterDto() + { + this.Sort = "Name"; + this.SortBy = AutoFilterer.Enums.Sorting.Descending; + } + + [ToLowerContainsComparison] + public string Name { get; set; } + + [ToLowerContainsComparison] + public string Surname { get; set; } + + public Range CreationDate { get; set; } + + public Range ModificationDate { get; set; } + public Range DeletionDate { get; set; } + } +} From c323dce83723e18252068391a3a06d616222e701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:33:05 +0300 Subject: [PATCH 44/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20Author=20Request=20D?= =?UTF-8?q?ata=20Transfer=20Object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Request/AuthorRequestDto.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sample/EasyRepository.Sample/Dtos/Request/AuthorRequestDto.cs diff --git a/sample/EasyRepository.Sample/Dtos/Request/AuthorRequestDto.cs b/sample/EasyRepository.Sample/Dtos/Request/AuthorRequestDto.cs new file mode 100644 index 0000000..6f34035 --- /dev/null +++ b/sample/EasyRepository.Sample/Dtos/Request/AuthorRequestDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample.Dtos.Request +{ + public class AuthorRequestDto + { + public string Name { get; set; } + + public string Surname { get; set; } + } +} From bf052e1e3308a446ea8fdddff317d5ef8b1f7960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:33:19 +0300 Subject: [PATCH 45/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20Book=20Filter=20Data?= =?UTF-8?q?=20Transfer=20Object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Request/BookFilterDto.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 sample/EasyRepository.Sample/Dtos/Request/BookFilterDto.cs diff --git a/sample/EasyRepository.Sample/Dtos/Request/BookFilterDto.cs b/sample/EasyRepository.Sample/Dtos/Request/BookFilterDto.cs new file mode 100644 index 0000000..746a9b2 --- /dev/null +++ b/sample/EasyRepository.Sample/Dtos/Request/BookFilterDto.cs @@ -0,0 +1,29 @@ +using AutoFilterer.Attributes; +using AutoFilterer.Types; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample.Dtos.Request +{ + [PossibleSortings("Title", "CreationDate", "ModificationDate", "DeletionDate")] + public class BookFilterDto : PaginationFilterBase + { + public BookFilterDto() + { + this.Sort = "Title"; + this.SortBy = AutoFilterer.Enums.Sorting.Descending; + } + + [ToLowerContainsComparison] + public string Title { get; set; } + + public Range TotalPage { get; set; } + + public Range CreationDate { get; set; } + + public Range ModificationDate { get; set; } + public Range DeletionDate { get; set; } + } +} From 912224c25bf3f56b40ba05902dfc471ca92132e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:35:00 +0300 Subject: [PATCH 46/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20Book=20Request=20Dat?= =?UTF-8?q?a=20Transfer=20Object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Request/BookRequestDto.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sample/EasyRepository.Sample/Dtos/Request/BookRequestDto.cs diff --git a/sample/EasyRepository.Sample/Dtos/Request/BookRequestDto.cs b/sample/EasyRepository.Sample/Dtos/Request/BookRequestDto.cs new file mode 100644 index 0000000..10bf2d5 --- /dev/null +++ b/sample/EasyRepository.Sample/Dtos/Request/BookRequestDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyRepository.Sample.Dtos.Request +{ + public class BookRequestDto + { + public string Title { get; set; } + + public int TotalPage { get; set; } + } +} From 2f4b0e8e24b6a7a611baf0cc7226a5a1db563c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:35:17 +0300 Subject: [PATCH 47/49] =?UTF-8?q?=F0=9F=94=A8=20Add=20AuthorId=20property?= =?UTF-8?q?=20on=20Book=20Entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/Entities/Book.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sample/EasyRepository.Sample/Entities/Book.cs b/sample/EasyRepository.Sample/Entities/Book.cs index e8d9087..3de8b61 100644 --- a/sample/EasyRepository.Sample/Entities/Book.cs +++ b/sample/EasyRepository.Sample/Entities/Book.cs @@ -10,6 +10,8 @@ public class Book : EasyBaseEntity { public string Title { get; set; } + public Guid AuthorId { get; set; } + public int TotalPage { get; set; } public virtual Author Author { get; set; } From 5f1b59c9b90217eb2e8c6b9ec0de5011c18fd1a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:35:37 +0300 Subject: [PATCH 48/49] =?UTF-8?q?=F0=9F=94=A8=20Implement=20controller=20r?= =?UTF-8?q?oute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/EasyRepository.Sample/Startup.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sample/EasyRepository.Sample/Startup.cs b/sample/EasyRepository.Sample/Startup.cs index b972147..694e372 100644 --- a/sample/EasyRepository.Sample/Startup.cs +++ b/sample/EasyRepository.Sample/Startup.cs @@ -82,15 +82,12 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) options.DisplayRequestDuration(); options.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None); options.RoutePrefix = "api-docs"; - options.SwaggerEndpoint("/swagger/EasyProfiler/swagger.json", "EasyProfilerSwagger"); + options.SwaggerEndpoint("/swagger/EasyRepository/swagger.json", "EasyProfilerSwagger"); }); app.UseDocumentation(opts => this.Configuration.Bind("DocumentationOptions", opts)); app.UseEndpoints(endpoints => { - endpoints.MapGet("/", async context => - { - await context.Response.WriteAsync("Hello World!"); - }); + endpoints.MapControllers(); }); } } From e1a6b54d47354b92fcd396a6d5bb309b43267b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20G=C3=BCng=C3=B6r?= Date: Sat, 27 Nov 2021 21:35:58 +0300 Subject: [PATCH 49/49] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Add=20database=20?= =?UTF-8?q?migration=20for=20relation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20211126210441_AddRelation.Designer.cs | 105 ++++++++++++++++++ .../Migrations/20211126210441_AddRelation.cs | 56 ++++++++++ .../SampleDbContextModelSnapshot.cs | 6 +- 3 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 sample/EasyRepository.Sample/Migrations/20211126210441_AddRelation.Designer.cs create mode 100644 sample/EasyRepository.Sample/Migrations/20211126210441_AddRelation.cs diff --git a/sample/EasyRepository.Sample/Migrations/20211126210441_AddRelation.Designer.cs b/sample/EasyRepository.Sample/Migrations/20211126210441_AddRelation.Designer.cs new file mode 100644 index 0000000..b02ee9e --- /dev/null +++ b/sample/EasyRepository.Sample/Migrations/20211126210441_AddRelation.Designer.cs @@ -0,0 +1,105 @@ +// +using System; +using EasyRepository.Sample.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace EasyRepository.Sample.Migrations +{ + [DbContext(typeof(SampleDbContext))] + [Migration("20211126210441_AddRelation")] + partial class AddRelation + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.12") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("DeletionDate") + .HasColumnType("timestamp without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Surname") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AuthorId") + .HasColumnType("uuid"); + + b.Property("CreationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("DeletionDate") + .HasColumnType("timestamp without time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationDate") + .HasColumnType("timestamp without time zone"); + + b.Property("Title") + .HasColumnType("text"); + + b.Property("TotalPage") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.ToTable("Books"); + }); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Book", b => + { + b.HasOne("EasyRepository.Sample.Entities.Author", "Author") + .WithMany("Books") + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Author"); + }); + + modelBuilder.Entity("EasyRepository.Sample.Entities.Author", b => + { + b.Navigation("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/sample/EasyRepository.Sample/Migrations/20211126210441_AddRelation.cs b/sample/EasyRepository.Sample/Migrations/20211126210441_AddRelation.cs new file mode 100644 index 0000000..4aee2e2 --- /dev/null +++ b/sample/EasyRepository.Sample/Migrations/20211126210441_AddRelation.cs @@ -0,0 +1,56 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace EasyRepository.Sample.Migrations +{ + public partial class AddRelation : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Books_Authors_AuthorId", + table: "Books"); + + migrationBuilder.AlterColumn( + name: "AuthorId", + table: "Books", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), + oldClrType: typeof(Guid), + oldType: "uuid", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Books_Authors_AuthorId", + table: "Books", + column: "AuthorId", + principalTable: "Authors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Books_Authors_AuthorId", + table: "Books"); + + migrationBuilder.AlterColumn( + name: "AuthorId", + table: "Books", + type: "uuid", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uuid"); + + migrationBuilder.AddForeignKey( + name: "FK_Books_Authors_AuthorId", + table: "Books", + column: "AuthorId", + principalTable: "Authors", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/sample/EasyRepository.Sample/Migrations/SampleDbContextModelSnapshot.cs b/sample/EasyRepository.Sample/Migrations/SampleDbContextModelSnapshot.cs index e8eae5c..f55df27 100644 --- a/sample/EasyRepository.Sample/Migrations/SampleDbContextModelSnapshot.cs +++ b/sample/EasyRepository.Sample/Migrations/SampleDbContextModelSnapshot.cs @@ -54,7 +54,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("AuthorId") + b.Property("AuthorId") .HasColumnType("uuid"); b.Property("CreationDate") @@ -86,7 +86,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.HasOne("EasyRepository.Sample.Entities.Author", "Author") .WithMany("Books") - .HasForeignKey("AuthorId"); + .HasForeignKey("AuthorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Author"); });