GenericRepo.EFCore
2.1.0
dotnet add package GenericRepo.EFCore --version 2.1.0
NuGet\Install-Package GenericRepo.EFCore -Version 2.1.0
<PackageReference Include="GenericRepo.EFCore" Version="2.1.0" />
paket add GenericRepo.EFCore --version 2.1.0
#r "nuget: GenericRepo.EFCore, 2.1.0"
// Install GenericRepo.EFCore as a Cake Addin
#addin nuget:?package=GenericRepo.EFCore&version=2.1.0
// Install GenericRepo.EFCore as a Cake Tool
#tool nuget:?package=GenericRepo.EFCore&version=2.1.0
GenericRepo.EFCore
Getting Started
You can install the latest package via Nuget package manager just search for GenericRepo.EFCore. You can also install via powershell using the following command.
Install-Package GenericRepo.EFCore -Version 2.1.0
Or via the donet CLI
dotnet add package GenericRepo.EFCore --version 2.1.0
Using the package
- Create a DbContext and its entities
public class GenericDbContext : DbContext
{
public GenericDbContext()
{
}
public GenericDbContext(DbContextOptions<GenericDbContext> options)
: base(options)
{
}
public DbSet<Car> Cars { get; set; }
public DbSet<Model> Models { get;set; }
public DbSet<Make> Makes { get; set; }
public DbSet<Owner> Owners {get;set; }
}
- Create a repository class that inherits GenericRepository<TEntity, TDbContext>
public class CarsRepository : GenericRepository<Car, GenericDbContext>
{
public CarsRepository(GenericDbContext dataContext) : base(dataContext)
{
}
}
In version 2.1.0 the GenericRepositoryFactory class was added. This is a thread safe class for use in stateful applications like Blazor Server etc. You use this class the same way as the GenericRepository class except you add a DBContextFactory<T> instead of a DBContext<T> to the services.
See Microsoft's Docs for more information DbContext Lifetime, Configuration, and Initialization
// GenericRepository
services.AddDbContext<GenericDbContext>();
// GenericRepositoryFactory
services.AddDbContextFactory<GenericDbContext>();
In version 2.0.0 + the ability to include related properties in the GetAll() and GetAllAsync() methods was added. The use is similar to that of the Get() and GetAsync() methods:
public class TestClass {
var repo = new CarsRepo();
var carQuery = repo.Cars.GetAll(x => x.Owners);
}
This is how you can use the Get and GetAsync methods to include properties in version 1.2.0 +:
public class TestClass {
var repo = new CarsRepo();
var carQuery = repo.Get(x => x.OwnerName == "Smith", x => x.Make, x => x.Model);
}
In version 1.0.0 you use the Get and GetAsync methods like this:
public class TestClass {
var repo = new CarsRepo();
var carQuery = repo.Get(x => x.OwnerName == "Smith", includedProperties: "Car.Make");
}
Thats it! This generic repository will give you access to the following generic methods:
- Get(object id)
- GetAsync(object id)
- Get(filter, includedProperties)
- GetAsync(filter, includedProperties)
- GetAll(includedProperties)
- GetAllAsync(includedProperties)
- Delete
- DeleteAsync
- Insert
- InsertAsync
- Update
- UpdateAsync
Special note: All methods are marked virtual. If you need to modify them for any reason, just override them
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.EntityFrameworkCore (>= 5.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
This release introduces the GenericRepositoryFactory class. This class is a thread safe class for use in stateful applications like Blazor Server