Skip to content

Commit

Permalink
6.0.2 release! (#37)
Browse files Browse the repository at this point in the history
* EFCore.QueryRepository.Tests Project added.

* Unit tests added.

* Prepared for 6.0.2 release

---------

Co-authored-by: Tanvir Arjel <[email protected]>
Co-authored-by: Tanvir Ahmad Arjel <[email protected]>
  • Loading branch information
3 people authored Nov 19, 2023
1 parent d7a70d4 commit dfc42fc
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[*.cs]

# CA1510: Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance
dotnet_diagnostic.CA1510.severity = none

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic.CA2007.severity = none

Expand Down
9 changes: 9 additions & 0 deletions EFCore.GenericRepository.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TanvirArjel.EFCore.GenericR
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TanvirArjel.EFCore.QueryRepository", "src\TanvirArjel.EFCore.QueryRepository\TanvirArjel.EFCore.QueryRepository.csproj", "{B27024B0-3436-4E8B-9E6C-0D3C6850EE95}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4704B96B-B9B8-4278-8581-15A16F254EA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.QueryRepository.Tests", "tests\EFCore.QueryRepository.Tests\EFCore.QueryRepository.Tests.csproj", "{45A7BACF-88A0-43F6-A64D-FD7E16047080}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -42,6 +46,10 @@ Global
{B27024B0-3436-4E8B-9E6C-0D3C6850EE95}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B27024B0-3436-4E8B-9E6C-0D3C6850EE95}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B27024B0-3436-4E8B-9E6C-0D3C6850EE95}.Release|Any CPU.Build.0 = Release|Any CPU
{45A7BACF-88A0-43F6-A64D-FD7E16047080}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45A7BACF-88A0-43F6-A64D-FD7E16047080}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45A7BACF-88A0-43F6-A64D-FD7E16047080}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45A7BACF-88A0-43F6-A64D-FD7E16047080}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -51,6 +59,7 @@ Global
{375C3AF5-6957-46D1-92F4-869C7E26DE5F} = {A54E2127-8988-46A4-858A-39A4553504C6}
{2D4EDBB7-8A7D-4348-881F-F670773401FA} = {98A19DB3-ED3F-4327-8F46-CE7C7D71EC65}
{B27024B0-3436-4E8B-9E6C-0D3C6850EE95} = {98A19DB3-ED3F-4327-8F46-CE7C7D71EC65}
{45A7BACF-88A0-43F6-A64D-FD7E16047080} = {4704B96B-B9B8-4278-8581-15A16F254EA0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B04FE49F-0045-4944-A589-88C8A33F7594}
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This library is a Generic Repository implementation for EF Core ORM which will r

## ⭐ Giving a star

**If you find this library useful, please don't forget to encouraging me to do such more stuffs by giving a star to this repository. Thank you.**
**If you find this library useful, please don't forget to encourage me to do such more stuffs by giving a star to this repository. Thank you.**

## 🔥 What's new

Expand Down Expand Up @@ -74,7 +74,7 @@ Install-Package TanvirArjel.EFCore.GenericRepository
dotnet add package TanvirArjel.EFCore.GenericRepository
```

Then in the `ConfirugeServices` method of the `Startup` class:
Then in the `ConfigureServices` method of the `Startup` class:

```C#
public void ConfigureServices(IServiceCollection services)
Expand Down Expand Up @@ -104,7 +104,7 @@ Install-Package TanvirArjel.EFCore.QueryRepository
dotnet add package TanvirArjel.EFCore.QueryRepository
```

Then in the `ConfirugeServices` method of the `Startup` class:
Then in the `ConfigureServices` method of the `Startup` class:

```C#
public void ConfigureServices(IServiceCollection services)
Expand All @@ -125,17 +125,17 @@ public class EmployeeService
{
// For query version, please use `IQueryRepository` instead of `IRepository`
private readonly IRepository _repository; // If single DbContext
private readonly IRepository<YourDbContext1> _dbConext1Repository; // If multiple DbContext
private readonly IRepository<YourDbContext1> _dbContext1Repository; // If multiple DbContext
public EmployeeService(IRepository repository, IRepository<YourDbContext1> dbConext1Repository)
public EmployeeService(IRepository repository, IRepository<YourDbContext1> dbContext1Repository)
{
_repository = repository;
_dbConext1Repository = dbConext1Repository;
_dbContext1Repository = dbContext1Repository;
}

public async Task<Employee> GetEmployeeAsync(int employeeId)
{
Employee employee = await _repository.GetByIdAsync<Employee>(1);
Employee employee = await _repository.GetByIdAsync<Employee>(employeeId);
return employee;
}
}
Expand All @@ -146,12 +146,12 @@ public class EmployeeService
public class EmployeeService
{
private readonly IRepository _repository; // If single DbContext
private readonly IRepository<YourDbContext1> _dbConext1Repository; // If multiple DbContext
private readonly IRepository<YourDbContext1> _dbContext1Repository; // If multiple DbContext
public EmployeeService(IRepository repository, IRepository<YourDbContext1> dbConext1Repository)
public EmployeeService(IRepository repository, IRepository<YourDbContext1> dbContext1Repository)
{
_repository = repository;
_dbConext1Repository = dbConext1Repository;
_dbContext1Repository = dbContext1Repository;
}

public async Task<int> CreateAsync(Employee employee)
Expand All @@ -164,4 +164,4 @@ public class EmployeeService
}
```

### For more detail documentaion, please visit [Documentation Wiki](https://github.com/TanvirArjel/EFCore.GenericRepository/wiki)
### For more detail documentation, please visit [Documentation Wiki](https://github.com/TanvirArjel/EFCore.GenericRepository/wiki)
11 changes: 6 additions & 5 deletions demo/AspNetCoreApp/AspNetCoreApp.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition=" '$(RunConfiguration)' == 'AspNetCore5._0' " />
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
<PackageReference Include="TanvirArjel.Extensions.Microsoft.DependencyInjection" Version="2.1.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion demo/AspNetCoreApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"AspNetCore5._0": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"dotnetRunMessages": "true"
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/UnitTest/UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
<Version>6.0.1</Version>
<Version>6.0.2</Version>
<LangVersion>8.0</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- <GeneratePackageOnBuild>true</GeneratePackageOnBuild> -->
Expand Down Expand Up @@ -75,7 +75,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0-*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
Expand Down
15 changes: 9 additions & 6 deletions src/TanvirArjel.EFCore.QueryRepository/QueryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
using Microsoft.EntityFrameworkCore.Query;

[assembly: InternalsVisibleTo("TanvirArjel.EFCore.GenericRepository")]
[assembly: InternalsVisibleTo("EFCore.QueryRepository.Tests")]

namespace TanvirArjel.EFCore.GenericRepository
{
[DebuggerStepThrough]
// [DebuggerStepThrough]
internal class QueryRepository<TDbContext> : IQueryRepository, IQueryRepository<TDbContext>
where TDbContext : DbContext
{
Expand Down Expand Up @@ -389,8 +390,10 @@ public async Task<TProjectedType> GetByIdAsync<T, TProjectedType>(

IQueryable<T> query = _dbContext.Set<T>();

return await query.Where(expressionTree).Select(selectExpression)
.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
return await query.Where(expressionTree)
.Select(selectExpression)
.FirstOrDefaultAsync(cancellationToken)
.ConfigureAwait(false);
}

public Task<T> GetAsync<T>(
Expand Down Expand Up @@ -550,11 +553,11 @@ public async Task<bool> ExistsByIdAsync<T>(object id, CancellationToken cancella
throw new ArgumentException("Entity does not have any primary key defined", nameof(id));
}

object primayKeyValue = null;
object primaryKeyValue = null;

try
{
primayKeyValue = Convert.ChangeType(id, primaryKeyType, CultureInfo.InvariantCulture);
primaryKeyValue = Convert.ChangeType(id, primaryKeyType, CultureInfo.InvariantCulture);
}
catch (Exception)
{
Expand All @@ -563,7 +566,7 @@ public async Task<bool> ExistsByIdAsync<T>(object id, CancellationToken cancella

ParameterExpression pe = Expression.Parameter(typeof(T), "entity");
MemberExpression me = Expression.Property(pe, primaryKeyName);
ConstantExpression constant = Expression.Constant(primayKeyValue, primaryKeyType);
ConstantExpression constant = Expression.Constant(primaryKeyValue, primaryKeyType);
BinaryExpression body = Expression.Equal(me, constant);
Expression<Func<T, bool>> expressionTree = Expression.Lambda<Func<T, bool>>(body, new[] { pe });

Expand Down
6 changes: 3 additions & 3 deletions src/TanvirArjel.EFCore.QueryRepository/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ public static async Task<PaginatedList<T>> ToPaginatedListAsync<T>(

if (specification.PageIndex < 1)
{
throw new ArgumentOutOfRangeException(nameof(specification.PageIndex), $"The value of {nameof(specification.PageIndex)} must be greater than 0.");
throw new ArgumentOutOfRangeException(nameof(specification), $"The value of {nameof(specification.PageIndex)} must be greater than 0.");
}

if (specification.PageSize < 1)
{
throw new ArgumentOutOfRangeException(nameof(specification.PageSize), $"The value of {nameof(specification.PageSize)} must be greater than 0.");
throw new ArgumentOutOfRangeException(nameof(specification), $"The value of {nameof(specification.PageSize)} must be greater than 0.");
}

IQueryable<T> countSource = source;

// modify the IQueryable using the specification's expression criteria
if (specification.Conditions != null && specification.Conditions.Any())
if (specification.Conditions != null && specification.Conditions.Count != 0)
{
foreach (Expression<Func<T, bool>> condition in specification.Conditions)
{
Expand Down
10 changes: 5 additions & 5 deletions src/TanvirArjel.EFCore.QueryRepository/SpecificationEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IQueryable<T> GetSpecifiedQuery<T>(this IQueryable<T> inputQuery,
{
if (specification.Skip < 0)
{
throw new ArgumentOutOfRangeException(nameof(specification.Skip), $"The value of {nameof(specification.Skip)} in {nameof(specification)} can not be negative.");
throw new ArgumentOutOfRangeException(nameof(specification), $"The value of {nameof(specification.Skip)} in {nameof(specification)} can not be negative.");
}

query = query.Skip((int)specification.Skip);
Expand All @@ -31,7 +31,7 @@ public static IQueryable<T> GetSpecifiedQuery<T>(this IQueryable<T> inputQuery,
{
if (specification.Take < 0)
{
throw new ArgumentOutOfRangeException(nameof(specification.Take), $"The value of {nameof(specification.Take)} in {nameof(specification)} can not be negative.");
throw new ArgumentOutOfRangeException(nameof(specification), $"The value of {nameof(specification.Take)} in {nameof(specification)} can not be negative.");
}

query = query.Take((int)specification.Take);
Expand All @@ -55,12 +55,12 @@ public static IQueryable<T> GetSpecifiedQuery<T>(this IQueryable<T> inputQuery,

if (specification.PageIndex < 1)
{
throw new ArgumentOutOfRangeException(nameof(specification.PageIndex), "The value of pageIndex must be greater than 0.");
throw new ArgumentOutOfRangeException(nameof(specification), "The value of specification.PageIndex must be greater than 0.");
}

if (specification.PageSize < 1)
{
throw new ArgumentOutOfRangeException(nameof(specification.PageSize), "The value of pageSize must be greater than 0.");
throw new ArgumentOutOfRangeException(nameof(specification), "The value of specification.PageSize must be greater than 0.");
}

IQueryable<T> query = GetSpecifiedQuery(inputQuery, (SpecificationBase<T>)specification);
Expand Down Expand Up @@ -89,7 +89,7 @@ public static IQueryable<T> GetSpecifiedQuery<T>(this IQueryable<T> inputQuery,
IQueryable<T> query = inputQuery;

// modify the IQueryable using the specification's criteria expression
if (specification.Conditions != null && specification.Conditions.Any())
if (specification.Conditions != null && specification.Conditions.Count != 0)
{
foreach (Expression<Func<T, bool>> specificationCondition in specification.Conditions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
<Version>1.5.1</Version>
<Version>1.5.2</Version>
<LangVersion>8.0</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- <GeneratePackageOnBuild>true</GeneratePackageOnBuild> -->
Expand Down Expand Up @@ -70,7 +70,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0-*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
Expand Down
45 changes: 45 additions & 0 deletions tests/EFCore.QueryRepository.Tests/DemoDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.EntityFrameworkCore;

namespace EFCore.QueryRepository.Tests;

public class DemoDbContext : DbContext
{
public DemoDbContext()
{
}

public DemoDbContext(DbContextOptions<DemoDbContext> options) : base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
if (modelBuilder == null)
{
throw new ArgumentNullException(nameof(modelBuilder));
}

base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Employee>().HasKey(e => e.Id);
}

public virtual DbSet<Employee> Employees { get; set; }
}

public class Employee
{
public int Id { get; set; }

public int DepartmentId { get; set; }

public string Name { get; set; }

public Department Department { get; set; }
}

public class Department
{
public int Id { get; set; }

public string Name { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq.EntityFrameworkCore" Version="7.0.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\TanvirArjel.EFCore.QueryRepository\TanvirArjel.EFCore.QueryRepository.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions tests/EFCore.QueryRepository.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Loading

0 comments on commit dfc42fc

Please sign in to comment.