Omnia.GenericImplementationEF
1.0.1
dotnet add package Omnia.GenericImplementationEF --version 1.0.1
NuGet\Install-Package Omnia.GenericImplementationEF -Version 1.0.1
<PackageReference Include="Omnia.GenericImplementationEF" Version="1.0.1" />
<PackageVersion Include="Omnia.GenericImplementationEF" Version="1.0.1" />
<PackageReference Include="Omnia.GenericImplementationEF" />
paket add Omnia.GenericImplementationEF --version 1.0.1
#r "nuget: Omnia.GenericImplementationEF, 1.0.1"
#:package Omnia.GenericImplementationEF@1.0.1
#addin nuget:?package=Omnia.GenericImplementationEF&version=1.0.1
#tool nuget:?package=Omnia.GenericImplementationEF&version=1.0.1
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. 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. |
-
net8.0
- AutoMapper (>= 14.0.0)
- LinqKit.Microsoft.EntityFrameworkCore (>= 8.1.5)
- Microsoft.AspNetCore (>= 2.3.0)
- Microsoft.EntityFrameworkCore (>= 8.0.10)
- Microsoft.EntityFrameworkCore.SqlServer.Abstractions (>= 9.0.4)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.10)
- Omnia.InterfaceUtility (>= 1.0.1)
- Omnia.Utility (>= 1.0.1)
- System.IdentityModel.Tokens.Jwt (>= 8.12.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.