GenericRepository.EFCore
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package GenericRepository.EFCore --version 1.0.1
NuGet\Install-Package GenericRepository.EFCore -Version 1.0.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="GenericRepository.EFCore" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GenericRepository.EFCore --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GenericRepository.EFCore, 1.0.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.
// Install GenericRepository.EFCore as a Cake Addin #addin nuget:?package=GenericRepository.EFCore&version=1.0.1 // Install GenericRepository.EFCore as a Cake Tool #tool nuget:?package=GenericRepository.EFCore&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
GenericRepository
- This is a generic repository of basic CRUD operation
- In This read entities with expression filters, sorting and include other dependent entities
- It also return a queryable entity on which you can apply other linq operation
How to Use
Method : 1
public interface IDb : IDisposable
{
IRepository<Category> Categories { get; }
IRepository<Product> Products { get; }
Task<int> SaveChangesAsync();
}
public class Db : IDb
{
private readonly AppDbContext _contex;
public Db(AppDbContext contex)
{
_contex = contex;
Categories = new Repository<Category, AppDbContext7gt;(_contex);
Products = new Repository<Product, AppDbContext>(_contex);
}
public IRepository<Category> Categories { get; private set; }
public IRepository<Product> Products { get; private set; }
public void Dispose()
=> _contex.Dispose();
public async Task<int> SaveChangesAsync()
=> await _contex.SaveChangesAsync();
}
In Program.cs
services.AddTransient<IDb, Db>();
Method : 2
public interface IProductRepository : IRepository<Product>
{
// your specific method
}
public class ProductRepository(TestDbContext context)
: Repository<Product, TestDbContext>(context), IProductRepository
{
// your specific method implemented
}
In Program.cs
services.AddTransient<ICategoryRepository, CategoryRepository>();
services.AddTransient<IProductRepository, ProductRepository>();
In Endpoint OR Controller
app.MapGet("/api/products", async (IProductRepository productRepository) =>
{
var products = await productRepository.GetItemsAsync()
return products;
})
app.MapPost("/api/product/create", async (IProductRepository productRepository, Product product) =>
{
await productRepository.CreateAsync(product);
await productRepository.SaveChanges()
return new { Product = product, Status = "Success" };
});
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.