{"id":20904734,"url":"https://github.com/angelodotnet/net8-efcore-genericrepository","last_synced_at":"2026-01-25T01:01:01.674Z","repository":{"id":230297445,"uuid":"770045093","full_name":"AngeloDotNet/NET8-EFCore-GenericRepository","owner":"AngeloDotNet","description":"Collection of a generic implementation of Entity Framework Core for .NET 8 mostly used in my private and/or work projects thus avoiding the duplication of repetitive code.","archived":false,"fork":false,"pushed_at":"2025-11-14T10:47:29.000Z","size":94,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-02T14:59:10.946Z","etag":null,"topics":["aspnetcore","c-sharp","entity-framework-core","generic-repository","hacktoberfest","hacktoberfest-accepted","nuget-package"],"latest_commit_sha":null,"homepage":"","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/AngeloDotNet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-03-10T19:07:53.000Z","updated_at":"2025-11-14T10:47:32.000Z","dependencies_parsed_at":"2024-03-29T00:20:59.322Z","dependency_job_id":"52b81044-377f-4e19-a178-5b11a363778e","html_url":"https://github.com/AngeloDotNet/NET8-EFCore-GenericRepository","commit_stats":null,"previous_names":["angelodotnet/net8-efcore-genericrepository"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/AngeloDotNet/NET8-EFCore-GenericRepository","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AngeloDotNet%2FNET8-EFCore-GenericRepository","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AngeloDotNet%2FNET8-EFCore-GenericRepository/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AngeloDotNet%2FNET8-EFCore-GenericRepository/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AngeloDotNet%2FNET8-EFCore-GenericRepository/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AngeloDotNet","download_url":"https://codeload.github.com/AngeloDotNet/NET8-EFCore-GenericRepository/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AngeloDotNet%2FNET8-EFCore-GenericRepository/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28740388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T22:12:27.248Z","status":"ssl_error","status_checked_at":"2026-01-24T22:12:10.529Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["aspnetcore","c-sharp","entity-framework-core","generic-repository","hacktoberfest","hacktoberfest-accepted","nuget-package"],"created_at":"2024-11-18T13:18:40.380Z","updated_at":"2026-01-25T01:01:01.665Z","avatar_url":"https://github.com/AngeloDotNet.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NET8 EFCore Generic Repository\nCollection of a generic implementation of Entity Framework Core for .NET 8 mostly used in my private and/or work projects thus avoiding the duplication of repetitive code.\n\n## Give a star\nIf you found this Implementation helpful or used it in your Projects, do give it a :star: on Github. Thanks!\n\n## Installation\nThe library is available on [NuGet](https://www.nuget.org/packages/ClassLibrary.EFCore) or run the following command in the .NET CLI:\n\n```bash\ndotnet add package ClassLibrary.EFCore\n```\n\n## How to use\n\n### Registering services\n\n```csharp\nservices.AddDbContext\u003cYourDbContext\u003e(options =\u003e options.UseSqlServer(Configuration.GetConnectionString(\"DefaultConnection\")));\nservices.AddScoped\u003cDbContext, YourDbContext\u003e();\nservices.AddScoped\u003cIRepository\u003cYourEntity, YourTypeEntityId\u003e, Repository\u003cYourEntity, YourTypeEntityId\u003e\u003e();\n```\n\nAlternatively the generic version of the repository can be registered as follows:\n\n```csharp\nservices.AddScoped(typeof(IRepository\u003c,\u003e), typeof(Repository\u003c,\u003e));\n```\n\n## Important\n\nIn this README the INT type is used as ID type, but it is also possible to use the GUID type, making the appropriate corrections later.\n\n## Example entity\n\n```csharp\npublic class YourEntity : IEntity\u003cint\u003e\n{\n    public int Id { get; set; }\n    public string Name { get; set; }\n    public string Description { get; set; }\n}\n```\n\n## Example interface\n\n```csharp\npublic interface IYourEntityService\n{\n    Task\u003cIQueryable\u003cYourEntity\u003e\u003e GetAllAsync(Func\u003cIQueryable\u003cYourEntity\u003e,\n        IIncludableQueryable\u003cYourEntity, object\u003e\u003e includes = null!,\n        Expression\u003cFunc\u003cYourEntity, bool\u003e\u003e filter = null!,\n        Expression\u003cFunc\u003cYourEntity, object\u003e\u003e orderBy = null!,\n        bool ascending = true);\n\n    Task\u003cYourEntity\u003e GetByIdAsync(int id);\n    Task CreateAsync(YourEntity entity);\n    Task UpdateAsync(YourEntity entity);\n    Task DeleteAsync(YourEntity entity);\n\n    //Alternative method for deleting\n    Task DeleteByIdAsync(int id);\n\n    //Optional method\n    Task\u003cPaginatedResult\u003cTEntity\u003e\u003e GetPaginatedAsync(IQueryable\u003cTEntity\u003e query, int pageNumber, int pageSize);\n\n    //Optional method for pagination (Prefer this method instead of GetPaginatedAsync)\n    Task\u003cPaginatedResult\u003cTEntity\u003e\u003e GetAllPagingAsync(int pageNumber, int pageSize, Func\u003cIQueryable\u003cTEntity\u003e,\n        IIncludableQueryable\u003cTEntity, object\u003e\u003e includes = null!, Expression\u003cFunc\u003cTEntity, bool\u003e\u003e filter = null!,\n        Expression\u003cFunc\u003cTEntity, object\u003e\u003e orderBy = null!, bool ascending = true);\n}\n```\n\n## Example class\n\n```csharp\npublic class YourEntityService : IYourEntityService\n{\n    private readonly IRepository\u003cYourEntity, int\u003e _repository;\n\n    public YourEntityService(IRepository\u003cYourEntity, int\u003e repository)\n    {\n        _repository = repository;\n    }\n\n    //This method accepts optional lambdas as input (includes, where, order by),\n    //while by default it is sorted in ascending order (set false if you want to sort in descending order)\n    public async Task\u003cIQueryable\u003cTEntity\u003e\u003e GetAllAsync()\n    {\n        return await _repository.GetAllAsync();\n    }\n\n    public async Task\u003cYourEntity\u003e GetByIdAsync(int id)\n    {\n        return await _repository.GetByIdAsync(id);\n    }\n\n    public async Task CreateAsync(YourEntity entity)\n    {\n        await _repository.CreateAsync(entity);\n    }\n\n    public async Task UpdateAsync(YourEntity entity)\n    {\n        await _repository.UpdateAsync(entity);\n    }\n\n    public async Task DeleteAsync(YourEntity entity)\n    {\n        await _repository.DeleteAsync(entity);\n    }\n\n    //Alternative method for deleting\n    public async Task DeleteByIdAsync(int id)\n    {\n        await _repository.DeleteByIdAsync(id);\n    }\n\n    //Optional method for pagination\n    //For optional lambdas read the comments of the GetAllAsync method\n    //A simple way to retrieve data is to call the GetAllAsync() method\n    //After retrieving the data, it will be possible to invoke the GetPaginatedAsync() method to have a paginated list\n    //Example: var query = await repository.GetAllAsync(); var result = await repository.GetPaginatedAsync(query, 1, 10);\n    public async Task\u003cPaginatedResult\u003cTEntity\u003e\u003e GetPaginatedAsync(IQueryable\u003cTEntity\u003e query, int pageNumber, int pageSize)\n    {\n        return await repository.GetPaginatedAsync(query, pageNumber, pageSize);\n    }\n\n    //Optional method for pagination (Prefer this method instead of GetPaginatedAsync)\n    public async Task\u003cPaginatedResult\u003cTEntity\u003e\u003e GetAllPagingAsync(int pageNumber, int pageSize, Func\u003cIQueryable\u003cTEntity\u003e,\n        IIncludableQueryable\u003cTEntity, object\u003e\u003e includes = null!, Expression\u003cFunc\u003cTEntity, bool\u003e\u003e filter = null!,\n        Expression\u003cFunc\u003cTEntity, object\u003e\u003e orderBy = null!, bool ascending = true)\n    {\n        return await repository.await repository.GetAllPagingAsync(pageNumber: 2, pageSize: 5, includes: q =\u003e q.Include(p =\u003e p.Indirizzo), filter: w =\u003e w.Id \u003c= 10);\n    }\n}\n```\n\n## Test results\n\n![Test Results](https://github.com/user-attachments/assets/ae02993c-6a9a-453b-961d-96c7f661d23e)\n\n\n## Contributing\n\nContributions and/or suggestions are always welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangelodotnet%2Fnet8-efcore-genericrepository","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangelodotnet%2Fnet8-efcore-genericrepository","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangelodotnet%2Fnet8-efcore-genericrepository/lists"}