{"id":17336216,"url":"https://github.com/alsami/entityframeworkcore.genericrepository","last_synced_at":"2025-08-30T17:12:34.683Z","repository":{"id":78582868,"uuid":"140950935","full_name":"alsami/EntityFrameworkCore.GenericRepository","owner":"alsami","description":null,"archived":false,"fork":false,"pushed_at":"2020-07-20T18:26:23.000Z","size":89,"stargazers_count":10,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-23T11:42:07.414Z","etag":null,"topics":["component-composition","entityframeworkcore-codefirst","genericrepository"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alsami.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-07-14T14:06:48.000Z","updated_at":"2023-06-29T00:44:04.000Z","dependencies_parsed_at":"2023-04-22T16:45:46.836Z","dependency_job_id":null,"html_url":"https://github.com/alsami/EntityFrameworkCore.GenericRepository","commit_stats":null,"previous_names":["cleancodelabs/entityframeworkcore.genericrepository"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/alsami/EntityFrameworkCore.GenericRepository","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FEntityFrameworkCore.GenericRepository","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FEntityFrameworkCore.GenericRepository/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FEntityFrameworkCore.GenericRepository/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FEntityFrameworkCore.GenericRepository/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alsami","download_url":"https://codeload.github.com/alsami/EntityFrameworkCore.GenericRepository/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alsami%2FEntityFrameworkCore.GenericRepository/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272878320,"owners_count":25008336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["component-composition","entityframeworkcore-codefirst","genericrepository"],"created_at":"2024-10-15T15:28:42.532Z","updated_at":"2025-08-30T17:12:34.676Z","avatar_url":"https://github.com/alsami.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EntityFrameworkCore.GenericRepository\n\n[![NuGet](https://img.shields.io/nuget/dt/CleanCodeLabs.EntityFrameworkCore.GenericRepository.svg)](https://www.nuget.org/packages/CleanCodeLabs.EntityFrameworkCore.GenericRepository)\n[![NuGet](https://img.shields.io/nuget/v/CleanCodeLabs.EntityFrameworkCore.GenericRepository.svg)](https://www.nuget.org/packages/CleanCodeLabs.EntityFrameworkCore.GenericRepository)\n[![NuGet](https://img.shields.io/nuget/vpre/CleanCodeLabs.EntityFrameworkCore.GenericRepository.svg)](https://www.nuget.org/packages/CleanCodeLabs.EntityFrameworkCore.GenericRepository)\n[![Build Status](https://travis-ci.com/cleancodelabs/EntityFrameworkCore.GenericRepository.svg?branch=master)](https://travis-ci.com/cleancodelabs/EntityFrameworkCore.GenericRepository)\n\nThis is a cross platform library and generic-repository implementation for [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore), written in `.netstandard 2.0`, that provides most of the functionalities available for the framework in a generic way.\n\n## Installation\n\nThis package is available via nuget. You can install it using Visual-Studio-Nuget-Browser or by using the dotnet-cli for your test-project.\n\n```unspecified\ndotnet add package CleanCodeLabs.EntityFrameworkCore.GenericRepository\n```\n\nIf you want to add a specific version of this package\n\n```unspecified\ndotnet add package CleanCodeLabs.EntityFrameworkCore.GenericRepository --version 1.0.0\n```\n\nFor more information please visit the official [dotnet-cli documentation](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-add-package).\n\n## Usage\n\nAssuming we have a model like this\n\n```csharp\n\npublic class Address : IEntity\u003cGuid\u003e // or use abstract GuidEntity \n{\n    public Guid Id { get; set; }\n\n    public string City { get; set; }\n\n    public string Street { get; set; }\n\n    public string PostalCode { get; set; }\n\n    public virtual Customer Customer { get; set; }\n\n    public Guid CustomerId { get; set; }\n}\n\n```\n\n```csharp\npublic class Customer : IEntity\u003cGuid\u003e // or use abstract GuidEntity \n{\n    public Guid Id { get; set; }\n\n    public string Name { get; set; }\n}\n```\n\nWe would create a `DbContext` like this\n\n```csharp\npublic class SampleDbContext : DbContext\n{\n    // or use dbcontext options\n    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\n    {\n        // you could also say\n        // optionsBuilder.UseSqlServer(\"MyConnectionString\")\n        // for instance you could inject your configuration and do it like\n        // configuration.GetConnectionString(\"MyDb\");\n        // or implement the constructor with `DbContextOptions`\n        optionsBuilder.UseInMemoryDatabase(\"SampleInMemoryDb\");\n    }\n\n    protected override void OnModelCreating(ModelBuilder modelBuilder)\n    {\n        var customerBuilder = modelBuilder.Entity\u003cCustomer\u003e();\n\n        customerBuilder.ToTable($\"{nameof(Customer)}s\");\n\n        customerBuilder.HasKey(customer =\u003e customer.Id);\n\n        customerBuilder.Property(customer =\u003e customer.Name)\n            .IsRequired();\n\n        customerBuilder.HasIndex(customer =\u003e customer.Name)\n            .IsUnique();\n\n        var addressBuilder = modelBuilder.Entity\u003cAddress\u003e();\n\n        addressBuilder.ToTable($\"{nameof(Address)}es\");\n\n        addressBuilder.HasKey(address =\u003e address.Id);\n\n        addressBuilder.Property(address =\u003e address.City)\n            .IsRequired();\n\n        addressBuilder.Property(address =\u003e address.Street)\n            .IsRequired();\n\n        addressBuilder.Property(address =\u003e address.PostalCode)\n            .IsRequired();\n\n        addressBuilder.HasOne(address =\u003e address.Customer)\n            .WithMany(customer =\u003e customer.Addresses)\n            .HasForeignKey(address =\u003e address.CustomerId)\n            .OnDelete(DeleteBehavior.Restrict);\n    }\n}\n```\nNow we can register our dependencies with `IServiceCollection` like this\n\n```csharp\nvar serviceProvider = new ServiceCollection()\n    .AddDbContext\u003cDbContext, SampleDbContext\u003e(ServiceLifetime.Transient); // or whatever you need here\n    // generic registration\n    .AddTransient(typeof(IEntityRepository\u003c,\u003e), typeof(EntityRepository\u003c,\u003e))\n    .AddTransient(typeof(IPagingRepository\u003c,\u003e), typeof(PagingRepository\u003c,\u003e)))\n    .BuildServiceProvider();\n\nvar customerRepository = serviceProvider.GetRequiredService\u003cIEntityRepository\u003cCustomer, Guid\u003e\u003e();\n\nvar google = new Customer\n{\n    Id = Guid.NewGuid(),\n    Name = \"Google\",\n    Addresses = new List\u003cAddress\u003e {\n        new Address {\n            Id = Guid.NewGuid(),\n            City = \"San Francisco\",\n            PostalCode = \"94043\",\n            Street = \"Silicon Valley area\"\n        }\n    }\n};\n\n// adding the customer and saving the changes\ncustomerRepository.Add(customer);\ncustomerRepository.EnsureChanges(); // this returns a bool when modifiedCount \u003e 0\n\n// now find the customer with an expression, also eager-load the addresses\n\nvar searchGoogle = customerRepository.Find(customer =\u003e customer.Name == \"Google\", customer =\u003e customer.Addresses);\n\n// we now should have customer google with one address included by eager-loading it\n```\n\nAll apis are available in a synchronous and asynchronous fashion.\n\nFor more information on how to use it, please have a look at the [samples](https://github.com/cleancodelabs/EntityFrameworkCore.GenericRepository/tree/master/samples).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsami%2Fentityframeworkcore.genericrepository","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falsami%2Fentityframeworkcore.genericrepository","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsami%2Fentityframeworkcore.genericrepository/lists"}