Nerest.EntityFrameworkToEFCore
1.0.4
dotnet add package Nerest.EntityFrameworkToEFCore --version 1.0.4
NuGet\Install-Package Nerest.EntityFrameworkToEFCore -Version 1.0.4
<PackageReference Include="Nerest.EntityFrameworkToEFCore" Version="1.0.4" />
paket add Nerest.EntityFrameworkToEFCore --version 1.0.4
#r "nuget: Nerest.EntityFrameworkToEFCore, 1.0.4"
// Install Nerest.EntityFrameworkToEFCore as a Cake Addin #addin nuget:?package=Nerest.EntityFrameworkToEFCore&version=1.0.4 // Install Nerest.EntityFrameworkToEFCore as a Cake Tool #tool nuget:?package=Nerest.EntityFrameworkToEFCore&version=1.0.4
Nerest.EntityFrameworkToEFCore
This tool will be helpful in order to create generic repositories accepting list of "include" expressions with nested "selects". By default this approach work only for Entity Framework but not for EF Core which requires "includes" and "thenIncludes". The tool translates the "EF-like" syntax to the EF Core in runtime and allows to make your BLL code abstract from the EF Core. Especially helpful for those who migrate their projects from EF to EF Core.
Example
Let's assume you have a UnitOfWork which creates GenericRepository:
public class GenericRepository: IGenericRepository<TEntity>
{
public GenericRepository(DbContext context)
{
_dbSet = context.Set<TEntity>();
}
public async Task<IReadOnlyCollection<TEntity>> GetAllAsync(params Expression<Func<TEntity, object>>[] includes)
{
return await _dbSet
.ApplyEntityFrameworkIncludes(includes) //this extension method applies includes in EF Core specific manner
.ToListAsync();
}
}
and then in BLL:
var repository = _unitOfWork.GetRepository<User>();
var users = await repository.GetAllAsync(u => u.Friends,
u => u.Role.Permissions,
u => u.Posts.Select(p => p.Comments.Select(c => c.Likes))
);
In runtime it will be translated into:
_dbSet.Include(u => u.Friends)
.Include(u => u.Role.Permissions)
.Include(u => Posts).ThenInclude(p => p.Comments).ThenInclude(c => c.Likes);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.EntityFrameworkCore (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.4 | 454 | 4/18/2023 |