Nerest.EntityFrameworkToEFCore
2.0.0
dotnet add package Nerest.EntityFrameworkToEFCore --version 2.0.0
NuGet\Install-Package Nerest.EntityFrameworkToEFCore -Version 2.0.0
<PackageReference Include="Nerest.EntityFrameworkToEFCore" Version="2.0.0" />
paket add Nerest.EntityFrameworkToEFCore --version 2.0.0
#r "nuget: Nerest.EntityFrameworkToEFCore, 2.0.0"
// Install Nerest.EntityFrameworkToEFCore as a Cake Addin #addin nuget:?package=Nerest.EntityFrameworkToEFCore&version=2.0.0 // Install Nerest.EntityFrameworkToEFCore as a Cake Tool #tool nuget:?package=Nerest.EntityFrameworkToEFCore&version=2.0.0
Nerest.EntityFrameworkToEFCore
This tool will be helpful for creating generic repositories that accept a list of "include" expressions with nested "selects". By default, this approach works only for Entity Framework, but not for EF Core, which requires "includes" and "thenIncludes". The tool translates the "EF-like" syntax to EF Core at runtime, allowing you to make your BLL code abstract from EF Core. It's especially helpful for those who are migrating 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 | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.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.