![]() |
VOOZH | about |
dotnet add package Extenso.Data.Entity --version 10.1.1
NuGet\Install-Package Extenso.Data.Entity -Version 10.1.1
<PackageReference Include="Extenso.Data.Entity" Version="10.1.1" />
<PackageVersion Include="Extenso.Data.Entity" Version="10.1.1" />Directory.Packages.props
<PackageReference Include="Extenso.Data.Entity" />Project file
paket add Extenso.Data.Entity --version 10.1.1
#r "nuget: Extenso.Data.Entity, 10.1.1"
#:package Extenso.Data.Entity@10.1.1
#addin nuget:?package=Extenso.Data.Entity&version=10.1.1Install as a Cake Addin
#tool nuget:?package=Extenso.Data.Entity&version=10.1.1Install as a Cake Tool
<img src="https://github.com/gordon-matt/Extenso/blob/master/_Misc/ExtensoLogo.png" alt="Logo" width="250" />
This package contains a generic IRepository<TEntity> and IMappedRepository<TModel, TEntity> implementations for Entity Framework,
as well as other data-related extension methods and helper classes.
The first thing you're going to need to do is have an IDbContextFactory implementation. Example:
public class ApplicationDbContextFactory : IDbContextFactory
{
private readonly IConfiguration configuration;
public ApplicationDbContextFactory(IConfiguration configuration)
{
this.configuration = configuration;
}
private DbContextOptions<ApplicationDbContext> options;
private DbContextOptions<ApplicationDbContext> Options
{
get
{
if (options == null)
{
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
optionsBuilder.UseSqlServer(configuration.GetConnectionString("DefaultConnection"));
options = optionsBuilder.Options;
}
return options;
}
}
public DbContext GetContext() => new ApplicationDbContext(Options);
public DbContext GetContext(string connectionString)
{
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
optionsBuilder.UseInMemoryDatabase(connectionString);
return new ApplicationDbContext(optionsBuilder.Options);
}
}
Next, you can register the EntityFrameworkRepository in your dependency injection container. An example:
// Regular direct to entity repository:
services.AddScoped(typeof(IRepository<>), typeof(EntityFrameworkRepository<>));
// Mapped repository, which maps between entities and models:
services.AddScoped(typeof(IMappedRepository<,>), typeof(ExtensoMapperEntityFrameworkRepository<,>));
// Or using the Extenso.Data.Entity.AutoMapper package, you could do this:
services.AddScoped(typeof(IMappedRepository<,>), typeof(AutoMapperEntityFrameworkRepository<,>));
Now just inject the repository into your classes and use it:
public class BlogService
{
private readonly IRepository<BlogCategory> blogCategoryService;
private readonly IRepository<BlogPost> blogPostService;
private readonly IRepository<BlogTag> blogTagService;
public BlogCategoryService(
IRepository<BlogCategory> blogCategoryService,
IRepository<BlogPost> blogPostService,
IRepository<BlogTag> blogTagService)
{
this.blogCategoryService = blogCategoryService;
this.blogPostService = blogPostService;
this.blogTagService = blogTagService;
}
public async Task<IEnumerable<BlogCategory>> GetCategoriesAsync(int tenantId) =>
await blogCategoryService.FindAsync(new SearchOptions<BlogCategory>
{
Query = x =>
x.TenantId == tenantId,
Include = query => query
.Include(x => x.Posts)
.ThenInclude(x => x.Tags),
OrderBy = query => query.OrderBy(x => x.Name),
SplitQuery = true, // Optional, defaults to false
});
// etc...
}
All CRUD operations are supported, including paging, searching, and sorting.
Even projections are supported via method overloads of Find(), FindAsync(), FindOne(), and FindOneAsync().
The mapped repositories are currently unable to support filtered includes. Either use the normal IRepository<> which does support that, or cast your IMappedRepository<,> to the relevant implementation and use GetContext() to run your own advanced queries that way. Example:
var efRepository = repository as ExtensoMapperEntityFrameworkRepository<ProductModelViewModel, ProductModel>;
using var context = efRepository.GetContext();
var advancedQuery = context.Set<ProductModel>()
.Include(x => x.Products)
.ThenInclude(x => x.ProductSubcategory)
.Include(x => x.ProductModelIllustrations)
.AsSplitQuery()
.IgnoreAutoIncludes()
.TagWith("My advanced query!")
.Where(x => x.ModifiedDate >= DateTime.UtcNow.AddYears(-10))
.ToList()
.Select(x => x.MapTo<ProductModelViewModel>())
.ToList();
Or simply just use your DbContext without any repository for those situations.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 3 NuGet packages that depend on Extenso.Data.Entity:
| Package | Downloads |
|---|---|
|
Extenso.AspNetCore.OData
Package Description |
|
|
Extenso.Data.Entity.AutoMapper
Package Description |
|
|
MantleFramework.Data.Abstractions
Mantle - Data - Abstractions |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.1.1 | 215 | 2/27/2026 |
| 10.1.0 | 155 | 2/24/2026 |
| 10.0.1 | 763 | 11/20/2025 |
| 10.0.0 | 360 | 11/13/2025 |
| 9.5.0 | 367 | 11/13/2025 |
| 9.4.0 | 323 | 6/16/2025 |
| 9.3.2 | 343 | 6/9/2025 |
| 9.3.1 | 292 | 6/2/2025 |
| 9.3.0 | 256 | 5/25/2025 |
| 9.2.0 | 225 | 5/3/2025 |
| 9.1.0 | 579 | 3/23/2025 |
| 9.0.0 | 287 | 1/4/2025 |
| 8.0.0 | 273 | 5/15/2024 |
| 7.0.0 | 1,303 | 11/27/2022 |
| 6.1.0 | 613 | 11/18/2022 |
| 6.0.2 | 2,475 | 5/21/2022 |
| 6.0.1 | 1,197 | 2/21/2022 |
| 6.0.0 | 1,010 | 1/14/2022 |
| 5.0.0 | 1,013 | 12/6/2020 |
| 3.1.0 | 13,508 | 6/15/2020 |