{"id":26067238,"url":"https://github.com/ainoraz/efcore.includebuilder","last_synced_at":"2025-04-11T17:12:40.562Z","repository":{"id":45477781,"uuid":"417912357","full_name":"AinoraZ/EFCore.IncludeBuilder","owner":"AinoraZ","description":"Entity Framework Core extension for improving Include syntax.","archived":false,"fork":false,"pushed_at":"2024-06-04T21:02:37.000Z","size":105,"stargazers_count":25,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T00:16:57.891Z","etag":null,"topics":["dotnet","efcore","extension","include","navigation"],"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/AinoraZ.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}},"created_at":"2021-10-16T18:21:56.000Z","updated_at":"2025-02-03T14:20:23.000Z","dependencies_parsed_at":"2024-06-04T22:28:27.573Z","dependency_job_id":"c2f6b0a1-1d3e-4c09-9919-17b4a8569f85","html_url":"https://github.com/AinoraZ/EFCore.IncludeBuilder","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AinoraZ%2FEFCore.IncludeBuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AinoraZ%2FEFCore.IncludeBuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AinoraZ%2FEFCore.IncludeBuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AinoraZ%2FEFCore.IncludeBuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AinoraZ","download_url":"https://codeload.github.com/AinoraZ/EFCore.IncludeBuilder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242610673,"owners_count":20157762,"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","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":["dotnet","efcore","extension","include","navigation"],"created_at":"2025-03-08T21:34:48.863Z","updated_at":"2025-03-08T21:34:49.400Z","avatar_url":"https://github.com/AinoraZ.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EFCore.IncludeBuilder\n\n[![NuGet](https://img.shields.io/nuget/v/Ainoraz.EFCore.IncludeBuilder)](https://www.nuget.org/packages/Ainoraz.EFCore.IncludeBuilder)\n[![Build](https://github.com/Ainoraz/EFCore.IncludeBuilder/actions/workflows/build-ci.yml/badge.svg)](https://github.com/AinoraZ/EFCore.IncludeBuilder/actions/workflows/build-ci.yml)\n\nExtension library for Entity Framework Core (6, 7) that tries to improve upon the ```Include(...).ThenInclude(...)``` syntax in order to better support the following scenarios:\n\n- Loading multiple entities on the same level (siblings).\n- Writing extension methods to include a whole set of entities at once.\n\n## Usage - Sibling Data\n\nEFCore.IncludeBuilder allows you to load sibling entities without going up the whole include structure.\n\n### ```UseIncludeBuilder()``` syntax\n\n```csharp\ndbContext.Users\n    .UseIncludeBuilder()\n    .Include(u =\u003e u.OwnedBlog, builder =\u003e builder\n        .Include(b =\u003e b.Posts.Where(p =\u003e p.PostDate \u003e DateTime.UtcNow.AddDays(-7)), builder =\u003e builder\n            .Include(p =\u003e p.Author)\n            .Include(p =\u003e p.Readers, builder =\u003e builder\n                .Include(r =\u003e r.ReadHistory)\n                .Include(r =\u003e r.Posts)\n            )\n        )\n    )\n    .Build()\n```\n\n\u003e ⚠️Caution: Autocomplete after List/Collection Includes is currently broken for VS and VSCode due to a bug in Roslyn. This is tracked by issue [#16](https://github.com/AinoraZ/EFCore.IncludeBuilder/issues/16). Regardless of autocomplete, **the code will still fully compile and work**.\n\n### ```Include(...).ThenInclude(...)``` syntax\n\n```csharp\ndbContext.Users\n    .Include(u =\u003e u.OwnedBlog)\n        .ThenInclude(b =\u003e b.Posts.Where(p =\u003e p.PostDate \u003e DateTime.UtcNow.AddDays(-7)))\n            .ThenInclude(p =\u003e p.Readers)\n                .ThenInclude(p =\u003e p.ReadHistory)\n    .Include(u =\u003e u.OwnedBlog)\n        .ThenInclude(b =\u003e b.Posts.Where(p =\u003e p.PostDate \u003e DateTime.UtcNow.AddDays(-7)))\n            .ThenInclude(p =\u003e p.Author)\n    .Include(u =\u003e u.OwnedBlog)\n        .ThenInclude(b =\u003e b.Posts.Where(p =\u003e p.PostDate \u003e DateTime.UtcNow.AddDays(-7)))\n            .ThenInclude(p =\u003e p.Readers)\n                .ThenInclude(p =\u003e p.Posts)\n\n```\n\n## Usage - Extension Methods\n\nSince IncludeBuilder uses the same ```Include(...)``` method signature for all levels, it is possible to write extension methods without depending on whether the includes are root level ```Include(...)``` on ```IQueryable``` or nested ```ThenInclude(...)``` on ```IIncludableQueryable```.\n\n### Extension method\n\n```csharp\npublic static TBuilder IncludeBlogChildren\u003cTBase, TBuilder\u003e(this IIncludeBuilder\u003cTBase, Blog, TBuilder\u003e blogBuilder)\n    where TBase : class\n    where TBuilder : IIncludeBuilder\u003cTBase, Blog, TBuilder\u003e\n    {\n    return blogBuilder\n        .Include(b =\u003e b.Author)\n        .Include(b =\u003e b.Posts, builder =\u003e builder\n            .Include(p =\u003e p.Readers)\n        );\n    }\n```\n\n### Root level extension usage\n\n```csharp\ndbContext.Blogs\n    .UseIncludeBuilder()\n    .IncludeBlogChildren()\n    .Build();\n```\n\n### Nested level extension usage\n\n```csharp\ndbContext.Users\n    .UseIncludeBuilder()\n    .Include(u =\u003e u.OwnedBlog, builder =\u003e builder\n        .IncludeBlogChildren()\n        .Include(b =\u003e b.Followers)\n    )\n    .Build();\n```\n\n## How It Works\n\nEFCore.IncludeBuilder converts the includes you give it back to ```Include(...).ThenInclude(...)``` calls, so it **_should_** support all the same providers and functionality as the original.\n\n## Performance\n\n```UseIncludeBuilder``` adds very little overhead both time and memory wise:\n\n| Method            |     Mean |    Error |   StdDev | Ratio | RatioSD | Allocated | Alloc Ratio |\n|-------------------|---------:|---------:|---------:|------:|--------:|----------:|------------:|\n| Include           | 30.89 μs | 0.572 μs | 0.535 μs |  1.00 |    0.00 |  10.53 KB |        1.00 |\n| UseIncludeBuilder | 33.50 μs | 0.163 μs | 0.136 μs |  1.08 |    0.02 |  11.91 KB |        1.13 |\n\nFor larger queries that duplicate the same filters, it can even be the faster option:\n\n| Method                   |     Mean |    Error |   StdDev | Ratio | Allocated | Alloc Ratio |\n|--------------------------|---------:|---------:|---------:|------:|----------:|------------:|\n| Include                  | 69.77 μs | 0.140 μs | 0.109 μs |  1.00 |   23.8 KB |        1.00 |\n| Include_DuplicatedFilter | 87.86 μs | 0.177 μs | 0.148 μs |  1.26 |  29.93 KB |        1.26 |\n| UseIncludeBuilder        | 78.62 μs | 0.213 μs | 0.167 μs |  1.13 |  25.34 KB |        1.07 |\n\nYou can find the most up to date benchmarks in the build artifacts for each build.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fainoraz%2Fefcore.includebuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fainoraz%2Fefcore.includebuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fainoraz%2Fefcore.includebuilder/lists"}