Omnia.GenericImplementationEF.Core 10.1.1

dotnet add package Omnia.GenericImplementationEF.Core --version 10.1.1
                    
NuGet\Install-Package Omnia.GenericImplementationEF.Core -Version 10.1.1
                    
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="Omnia.GenericImplementationEF.Core" Version="10.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Omnia.GenericImplementationEF.Core" Version="10.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Omnia.GenericImplementationEF.Core" />
                    
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 Omnia.GenericImplementationEF.Core --version 10.1.1
                    
#r "nuget: Omnia.GenericImplementationEF.Core, 10.1.1"
                    
#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.
#:package Omnia.GenericImplementationEF.Core@10.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Omnia.GenericImplementationEF.Core&version=10.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Omnia.GenericImplementationEF.Core&version=10.1.1
                    
Install as a Cake Tool

Omnia.GenericImplementationEF

Implementazioni generiche pronte all'uso per Entity Framework Core nel framework Omnia. Fornisce repository, servizi e utility per accelerare lo sviluppo con pattern consolidati.

Funzionalità

🗃️ Generic Repository

  • GenericRepository<T> - Repository completo per Entity Framework
  • Unit of Work Pattern - Gestione transazioni
  • Async/Await Support - Operazioni asincrone
  • Advanced Querying - Query complesse con LinqKit

🔧 Utility Avanzate

  • AutoMapperHelper - Configurazione automatica mapping
  • PredicateUtility - Builder per query dinamiche
  • SingletonUtility - Pattern singleton thread-safe
  • Query Optimization - Performance avanzate

📊 Paginazione e Filtering

  • Paginazione avanzata - Con sorting e filtering
  • Dynamic Queries - Query costruite runtime
  • Expression Trees - Predicati dinamici
  • Performance Optimized - Query efficienti

Installazione

dotnet add package Omnia.GenericImplementationEF

Utilizzo Base

Configurazione in Program.cs

using Omnia.GenericImplementationEF;

var builder = WebApplication.CreateBuilder(args);

// Aggiungi DbContext
builder.Services.AddDbContext<MyDbContext>(options =>
    options.UseSqlServer(connectionString));

// Aggiungi repository generici
builder.Services.AddOmniaGenericEF<MyDbContext>();

var app = builder.Build();

Repository Generico

public class ProductService
{
    private readonly GenericRepository<Product> _repository;

    public ProductService(GenericRepository<Product> repository)
    {
        _repository = repository;
    }

    public async Task<Product> GetByIdAsync(int id)
    {
        return await _repository.GetByIdAsync(id);
    }

    public async Task<PagedResult<Product>> GetPagedAsync(PaginationRequest request)
    {
        return await _repository.GetPagedAsync(request);
    }
}

Query Dinamiche

using Omnia.GenericImplementationEF;

public async Task<IEnumerable<Product>> SearchProducts(string name, decimal? minPrice)
{
    var predicate = PredicateUtility
        .Begin<Product>()
        .And(p => p.Name.Contains(name))
        .AndIf(minPrice.HasValue, p => p.Price >= minPrice.Value)
        .Build();

    return await _repository.FindAsync(predicate);
}

AutoMapper Helper

public class ProductProfile : Profile
{
    public ProductProfile()
    {
        AutoMapperHelper.CreateMap<Product, ProductDto>(this);
        AutoMapperHelper.CreateMap<ProductDto, Product>(this);
    }
}

Classi Principali

GenericRepository<T>

public class GenericRepository<T> : IGenericRepository<T> where T : class
{
    public async Task<T> GetByIdAsync(object id);
    public async Task<IEnumerable<T>> GetAllAsync();
    public async Task<IEnumerable<T>> FindAsync(Expression<Func<T, bool>> predicate);
    public async Task<PagedResult<T>> GetPagedAsync(PaginationRequest request);
    public async Task<T> AddAsync(T entity);
    public async Task<T> UpdateAsync(T entity);
    public async Task<bool> DeleteAsync(object id);
    public async Task<int> SaveChangesAsync();
}

PredicateUtility

public class PredicateUtility<T>
{
    public static PredicateBuilder<T> Begin();
    public PredicateBuilder<T> And(Expression<Func<T, bool>> predicate);
    public PredicateBuilder<T> Or(Expression<Func<T, bool>> predicate);
    public PredicateBuilder<T> AndIf(bool condition, Expression<Func<T, bool>> predicate);
    public Expression<Func<T, bool>> Build();
}

AutoMapperHelper

public static class AutoMapperHelper
{
    public static void CreateMap<TSource, TDestination>(Profile profile);
    public static void CreateTwoWayMap<T1, T2>(Profile profile);
    public static void ConfigureIgnore<TSource, TDestination>(
        IMappingExpression<TSource, TDestination> mapping, 
        params string[] propertyNames);
}

Esempi Avanzati

Repository Personalizzato

public class ProductRepository : GenericRepository<Product>
{
    public ProductRepository(DbContext context) : base(context) { }

    public async Task<IEnumerable<Product>> GetByCategory(string category)
    {
        var predicate = PredicateUtility
            .Begin<Product>()
            .And(p => p.Category == category)
            .And(p => p.IsActive)
            .Build();

        return await FindAsync(predicate);
    }

    public async Task<PagedResult<Product>> SearchProducts(ProductSearchRequest request)
    {
        var predicate = PredicateUtility
            .Begin<Product>()
            .AndIf(!string.IsNullOrEmpty(request.Name), p => p.Name.Contains(request.Name))
            .AndIf(request.MinPrice.HasValue, p => p.Price >= request.MinPrice)
            .AndIf(request.MaxPrice.HasValue, p => p.Price <= request.MaxPrice)
            .AndIf(!string.IsNullOrEmpty(request.Category), p => p.Category == request.Category)
            .Build();

        return await GetPagedAsync(predicate, request.Page, request.PageSize, request.OrderBy);
    }
}

Service con Transaction

public class OrderService
{
    private readonly GenericRepository<Order> _orderRepo;
    private readonly GenericRepository<OrderItem> _itemRepo;

    public async Task<Order> CreateOrderAsync(CreateOrderRequest request)
    {
        using var transaction = await _orderRepo.BeginTransactionAsync();
        
        try
        {
            var order = new Order { CustomerId = request.CustomerId };
            await _orderRepo.AddAsync(order);

            foreach (var item in request.Items)
            {
                item.OrderId = order.Id;
                await _itemRepo.AddAsync(item);
            }

            await _orderRepo.SaveChangesAsync();
            await transaction.CommitAsync();
            
            return order;
        }
        catch
        {
            await transaction.RollbackAsync();
            throw;
        }
    }
}

Dipendenze

  • AutoMapper - Object mapping
  • LinqKit.Microsoft.EntityFrameworkCore - Dynamic queries
  • Microsoft.AspNetCore - Web framework integration
  • Entity Framework Core - ORM

Compatibilità

  • .NET 8.0 o superiore
  • Entity Framework Core 8.0 o superiore
  • AutoMapper 14.0 o superiore

Performance

Query Ottimizzate - Include/ThenInclude automatici
Lazy Loading - Caricamento intelligente
Caching - Cache integrata per query frequenti
Bulk Operations - Operazioni batch
Connection Pooling - Pool di connessioni

Testing

La libreria include helper per unit testing:

[Test]
public async Task TestProductRepository()
{
    using var context = TestDbContextFactory.Create();
    var repository = new GenericRepository<Product>(context);

    var product = new Product { Name = "Test Product" };
    await repository.AddAsync(product);

    var result = await repository.GetByIdAsync(product.Id);
    Assert.NotNull(result);
}

Licenza

LGPL-3.0-or-later

Autore

Luca Gualandi - Framework Omnia

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Omnia.GenericImplementationEF.Core:

Package Downloads
Omnia.GenericImplementationEF.SqlServer

Implementazione SQL Server per Omnia GenericImplementationEF - PredicateBuilder per Microsoft SQL Server

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.1.1 99 4/30/2026