Extenso.Data.Entity 9.3.2

dotnet add package Extenso.Data.Entity --version 9.3.2
                    
NuGet\Install-Package Extenso.Data.Entity -Version 9.3.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Extenso.Data.Entity" Version="9.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Extenso.Data.Entity" Version="9.3.2" />
                    
Directory.Packages.props
<PackageReference Include="Extenso.Data.Entity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Extenso.Data.Entity --version 9.3.2
                    
#r "nuget: Extenso.Data.Entity, 9.3.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Extenso.Data.Entity&version=9.3.2
                    
Install Extenso.Data.Entity as a Cake Addin
#tool nuget:?package=Extenso.Data.Entity&version=9.3.2
                    
Install Extenso.Data.Entity as a Cake Tool

NuGet NuGet

<img src="https://github.com/gordon-matt/Extenso/blob/master/_Misc/ExtensoLogo.png" alt="Logo" width="250" />

Extenso.Data.Entity

Intro

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.

Getting Started

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().

Limitations

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();
Product 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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Extenso.Data.Entity:

Package Downloads
Extenso.AspNetCore.OData

Package Description

MantleFramework.Data.Abstractions

Package Description

Extenso.Data.Entity.AutoMapper

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.3.2 200 6/9/2025
9.3.1 139 6/2/2025
9.3.0 103 5/25/2025
9.2.0 82 5/3/2025
9.1.0 290 3/23/2025
9.0.0 151 1/4/2025
8.0.0 153 5/15/2024
7.0.0 909 11/27/2022
6.1.0 481 11/18/2022
6.0.2 2,079 5/21/2022
6.0.1 1,016 2/21/2022
6.0.0 844 1/14/2022
5.0.0 839 12/6/2020
3.1.0 12,937 6/15/2020
2.0.1 817 3/22/2020
2.0.0 976 2/24/2020
1.2.1 695 9/10/2019
1.2.0 1,036 2/27/2019
1.1.3 1,098 10/26/2018
1.1.2 1,535 6/30/2018
1.1.0 1,433 6/20/2018
1.0.1 1,214 5/23/2018
1.0.0 1,605 5/17/2018