GenericRepo.EFCore 2.1.0

dotnet add package GenericRepo.EFCore --version 2.1.0
NuGet\Install-Package GenericRepo.EFCore -Version 2.1.0
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="GenericRepo.EFCore" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GenericRepo.EFCore --version 2.1.0
#r "nuget: GenericRepo.EFCore, 2.1.0"
#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 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

  1. 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; }
}
  1. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 461 3/21/2022
2.0.0 413 3/13/2022
1.2.0 365 8/3/2021
1.0.0 335 8/1/2021

This release introduces the GenericRepositoryFactory class. This class is a thread safe class for use in stateful applications like Blazor Server