├── .gitattributes
├── .github
└── workflows
│ └── dotnet.yml
├── .gitignore
├── Directory.Build.props
├── EFCore.InMemory.HierarchyId.Test
├── DatabaseContextTests.cs
├── EFCore.InMemory.HierarchyId.Test.csproj
└── Test
│ └── Models
│ ├── AbrahamicContext.cs
│ └── Patriarch.cs
├── EFCore.InMemory.HierarchyId
├── EFCore.InMemory.HierarchyId.csproj
├── Extensions
│ ├── InMemoryHierarchyIdDbContextOptionsBuilderExtensions.cs
│ └── InMemoryHierarchyIdServiceCollectionExtensions.cs
├── Infrastructure
│ └── InMemoryHierarchyIdOptionsExtension.cs
├── Properties
│ ├── Resources.Designer.cs
│ └── Resources.resx
└── Storage
│ ├── InMemoryHierarchyIdTypeMapping.cs
│ └── InMemoryHierarchyIdTypeMappingSourcePlugin.cs
├── EFCore.SqlServer.HierarchyId.sln
├── LICENSE
├── NuGet.Config
├── README.md
└── key.snk
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 | *.cs diff=csharp
3 |
--------------------------------------------------------------------------------
/.github/workflows/dotnet.yml:
--------------------------------------------------------------------------------
1 | name: .NET
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | pull_request:
8 | branches:
9 | - main
10 |
11 | jobs:
12 | build:
13 |
14 | runs-on: windows-latest
15 |
16 | steps:
17 | - uses: actions/checkout@v3
18 | - name: Setup .NET
19 | uses: actions/setup-dotnet@v3
20 | with:
21 | dotnet-version: 9.0.x
22 | - name: Restore dependencies
23 | run: dotnet restore
24 | - name: Build
25 | run: dotnet build --no-restore --configuration Release
26 | - name: Upload artifacts
27 | uses: actions/upload-artifact@v3
28 | with:
29 | path: |
30 | **\\*.nupkg
31 | **\\*.snupkg
32 | - name: Test
33 | run: dotnet test --no-build --verbosity normal --configuration Release
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.tlog
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.)
298 | *.vbp
299 |
300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project)
301 | *.dsw
302 | *.dsp
303 |
304 | # Visual Studio 6 technical files
305 | *.ncb
306 | *.aps
307 |
308 | # Visual Studio LightSwitch build output
309 | **/*.HTMLClient/GeneratedArtifacts
310 | **/*.DesktopClient/GeneratedArtifacts
311 | **/*.DesktopClient/ModelManifest.xml
312 | **/*.Server/GeneratedArtifacts
313 | **/*.Server/ModelManifest.xml
314 | _Pvt_Extensions
315 |
316 | # Paket dependency manager
317 | .paket/paket.exe
318 | paket-files/
319 |
320 | # FAKE - F# Make
321 | .fake/
322 |
323 | # CodeRush personal settings
324 | .cr/personal
325 |
326 | # Python Tools for Visual Studio (PTVS)
327 | __pycache__/
328 | *.pyc
329 |
330 | # Cake - Uncomment if you are using it
331 | # tools/**
332 | # !tools/packages.config
333 |
334 | # Tabs Studio
335 | *.tss
336 |
337 | # Telerik's JustMock configuration file
338 | *.jmconfig
339 |
340 | # BizTalk build output
341 | *.btp.cs
342 | *.btm.cs
343 | *.odx.cs
344 | *.xsd.cs
345 |
346 | # OpenCover UI analysis results
347 | OpenCover/
348 |
349 | # Azure Stream Analytics local run output
350 | ASALocalRun/
351 |
352 | # MSBuild Binary and Structured Log
353 | *.binlog
354 |
355 | # NVidia Nsight GPU debugger configuration file
356 | *.nvuser
357 |
358 | # MFractors (Xamarin productivity tool) working folder
359 | .mfractor/
360 |
361 | # Local History for Visual Studio
362 | .localhistory/
363 |
364 | # Visual Studio History (VSHistory) files
365 | .vshistory/
366 |
367 | # BeatPulse healthcheck temp database
368 | healthchecksdb
369 |
370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
371 | MigrationBackup/
372 |
373 | # Ionide (cross platform F# VS Code tools) working folder
374 | .ionide/
375 |
376 | # Fody - auto-generated XML schema
377 | FodyWeavers.xsd
378 |
379 | # VS Code files for those working on multiple tools
380 | .vscode/*
381 | !.vscode/settings.json
382 | !.vscode/tasks.json
383 | !.vscode/launch.json
384 | !.vscode/extensions.json
385 | *.code-workspace
386 |
387 | # Local History for Visual Studio Code
388 | .history/
389 |
390 | # Windows Installer files from build outputs
391 | *.cab
392 | *.msi
393 | *.msix
394 | *.msm
395 | *.msp
396 |
397 | # JetBrains Rider
398 | *.sln.iml
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 | $(MSBuildThisFileDirectory)key.snk
6 | strict
7 | latest
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId.Test/DatabaseContextTests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using Microsoft.EntityFrameworkCore.SqlServer.Test.Models;
3 | using Xunit;
4 |
5 | namespace Microsoft.EntityFrameworkCore.SqlServer
6 | {
7 | public class DatabaseContextTests
8 | {
9 | [Fact]
10 | public void Should_CreateDatabaseContext()
11 | {
12 | // Arrange
13 | var databaseContext = new AbrahamicContext();
14 |
15 | // Act
16 | databaseContext.Database.EnsureCreated();
17 |
18 | // Assert
19 | Assert.NotNull(databaseContext);
20 | Assert.NotNull(databaseContext.Patriarchy);
21 | Assert.Equal(16, databaseContext.Patriarchy.Count());
22 | }
23 |
24 | [Fact]
25 | public void Should_GetEphraimEntryByName()
26 | {
27 | // Arrange
28 | var databaseContext = new AbrahamicContext();
29 |
30 | // Act
31 | databaseContext.Database.EnsureCreated();
32 | var ephraim = databaseContext.Patriarchy.Single(w => w.Name == "Ephraim");
33 |
34 | // Assert
35 | Assert.Equal(HierarchyId.Parse("/1/1/11.1/"), ephraim.Id);
36 | }
37 |
38 | [Fact]
39 | public void Should_GetEphraimEntryById()
40 | {
41 | // Arrange
42 | var databaseContext = new AbrahamicContext();
43 |
44 | // Act
45 | databaseContext.Database.EnsureCreated();
46 | var ephraim = databaseContext.Patriarchy.Single(w => w.Id == HierarchyId.Parse("/1/1/11.1/"));
47 |
48 | // Assert
49 | Assert.Equal("Ephraim", ephraim.Name);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId.Test/EFCore.InMemory.HierarchyId.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net9.0
5 | false
6 | EntityFrameworkCore.InMemory.HierarchyId.Test
7 | Microsoft.EntityFrameworkCore.InMemory
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId.Test/Test/Models/AbrahamicContext.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.EntityFrameworkCore.SqlServer.Test.Models
2 | {
3 | class AbrahamicContext : DbContext
4 | {
5 | public DbSet Patriarchy { get; set; }
6 |
7 | protected override void OnConfiguring(DbContextOptionsBuilder options)
8 | => options
9 | .UseInMemoryDatabase(
10 | "HierarchyIdTests",
11 | x => x.UseHierarchyId()
12 | );
13 |
14 | protected override void OnModelCreating(ModelBuilder modelBuilder)
15 | => modelBuilder.Entity()
16 | .HasData(
17 | new Patriarch { Id = HierarchyId.GetRoot(), Name = "Abraham" },
18 | new Patriarch { Id = HierarchyId.Parse("/1/"), Name = "Isaac" },
19 | new Patriarch { Id = HierarchyId.Parse("/1/1/"), Name = "Jacob" },
20 | new Patriarch { Id = HierarchyId.Parse("/1/1/1/"), Name = "Reuben" },
21 | new Patriarch { Id = HierarchyId.Parse("/1/1/2/"), Name = "Simeon" },
22 | new Patriarch { Id = HierarchyId.Parse("/1/1/3/"), Name = "Levi" },
23 | new Patriarch { Id = HierarchyId.Parse("/1/1/4/"), Name = "Judah" },
24 | new Patriarch { Id = HierarchyId.Parse("/1/1/5/"), Name = "Issachar" },
25 | new Patriarch { Id = HierarchyId.Parse("/1/1/6/"), Name = "Zebulun" },
26 | new Patriarch { Id = HierarchyId.Parse("/1/1/7/"), Name = "Dan" },
27 | new Patriarch { Id = HierarchyId.Parse("/1/1/8/"), Name = "Naphtali" },
28 | new Patriarch { Id = HierarchyId.Parse("/1/1/9/"), Name = "Gad" },
29 | new Patriarch { Id = HierarchyId.Parse("/1/1/10/"), Name = "Asher" },
30 | new Patriarch { Id = HierarchyId.Parse("/1/1/11.1/"), Name = "Ephraim" },
31 | new Patriarch { Id = HierarchyId.Parse("/1/1/11.2/"), Name = "Manasseh" },
32 | new Patriarch { Id = HierarchyId.Parse("/1/1/12/"), Name = "Benjamin" });
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId.Test/Test/Models/Patriarch.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.EntityFrameworkCore.SqlServer.Test.Models
2 | {
3 | class Patriarch
4 | {
5 | public HierarchyId Id { get; set; }
6 | public string Name { get; set; }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId/EFCore.InMemory.HierarchyId.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | EntityFrameworkCore.InMemory.HierarchyId
6 | Microsoft.EntityFrameworkCore.InMemory
7 | Adrian Paul Nutiu
8 | Adds hierarchyid support to the in-memory EF Core provider
9 | EFCore;InMemory;HierarchyId
10 | true
11 | true
12 | https://github.com/efcore/EFCore.SqlServer.HierarchyId
13 | © 2023 Brice Lambson, et al. All rights reserved.
14 | 8.0.0
15 | MIT
16 | https://github.com/efcore/EFCore.SqlServer.HierarchyId/releases
17 | true
18 | true
19 | true
20 | snupkg
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | True
32 | True
33 | Resources.resx
34 |
35 |
36 |
37 |
38 |
39 | ResXFileCodeGenerator
40 | Resources.Designer.cs
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId/Extensions/InMemoryHierarchyIdDbContextOptionsBuilderExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Infrastructure;
2 | using Microsoft.EntityFrameworkCore.InMemory.Infrastructure;
3 |
4 | namespace Microsoft.EntityFrameworkCore
5 | {
6 | ///
7 | /// HierarchyId specific extension methods for .
8 | ///
9 | public static class InMemoryHierarchyIdDbContextOptionsBuilderExtensions
10 | {
11 | ///
12 | /// Enable HierarchyId mappings.
13 | ///
14 | /// The builder being used to configure in-memory database.
15 | /// The options builder so that further configuration can be chained.
16 | public static InMemoryDbContextOptionsBuilder UseHierarchyId(
17 | this InMemoryDbContextOptionsBuilder optionsBuilder)
18 | {
19 | var coreOptionsBuilder = ((IInMemoryDbContextOptionsBuilderInfrastructure)optionsBuilder).OptionsBuilder;
20 |
21 | var extension = coreOptionsBuilder.Options.FindExtension()
22 | ?? new InMemoryHierarchyIdOptionsExtension();
23 |
24 | ((IDbContextOptionsBuilderInfrastructure)coreOptionsBuilder).AddOrUpdateExtension(extension);
25 |
26 | return optionsBuilder;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId/Extensions/InMemoryHierarchyIdServiceCollectionExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Infrastructure;
2 | using Microsoft.EntityFrameworkCore.InMemory.Storage;
3 | using Microsoft.EntityFrameworkCore.Storage;
4 |
5 | namespace Microsoft.Extensions.DependencyInjection
6 | {
7 | ///
8 | /// EntityFrameworkCore.InMemory.HierarchyId extension methods for .
9 | ///
10 | public static class InMemoryHierarchyIdServiceCollectionExtensions
11 | {
12 | ///
13 | /// Adds the services required for HierarchyId support in the in-memory database provider for Entity Framework.
14 | ///
15 | /// The to add services to.
16 | /// The same service collection so that multiple calls can be chained.
17 | public static IServiceCollection AddEntityFrameworkInMemoryHierarchyId(
18 | this IServiceCollection serviceCollection)
19 | {
20 | new EntityFrameworkServicesBuilder(serviceCollection)
21 | .TryAdd();
22 |
23 | return serviceCollection;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId/Infrastructure/InMemoryHierarchyIdOptionsExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.InMemory.Properties;
6 | using Microsoft.EntityFrameworkCore.InMemory.Storage;
7 | using Microsoft.EntityFrameworkCore.Storage;
8 | using Microsoft.Extensions.DependencyInjection;
9 |
10 | namespace Microsoft.EntityFrameworkCore.InMemory.Infrastructure
11 | {
12 | internal class InMemoryHierarchyIdOptionsExtension : IDbContextOptionsExtension
13 | {
14 | private DbContextOptionsExtensionInfo _info;
15 |
16 | public DbContextOptionsExtensionInfo Info => _info ??= new ExtensionInfo(this);
17 |
18 | public virtual void ApplyServices(IServiceCollection services)
19 | {
20 | services.AddEntityFrameworkInMemoryHierarchyId();
21 | }
22 |
23 | public virtual void Validate(IDbContextOptions options)
24 | {
25 | var internalServiceProvider = options.FindExtension()?.InternalServiceProvider;
26 | if (internalServiceProvider != null)
27 | {
28 | using (var scope = internalServiceProvider.CreateScope())
29 | {
30 | if (scope.ServiceProvider.GetService>()
31 | ?.Any(s => s is InMemoryHierarchyIdTypeMappingSourcePlugin) != true)
32 | {
33 | throw new InvalidOperationException(Resources.ServicesMissing);
34 | }
35 | }
36 | }
37 | }
38 |
39 | private sealed class ExtensionInfo : DbContextOptionsExtensionInfo
40 | {
41 | public ExtensionInfo(IDbContextOptionsExtension extension)
42 | : base(extension)
43 | {
44 | }
45 |
46 | private new InMemoryHierarchyIdOptionsExtension Extension
47 | => (InMemoryHierarchyIdOptionsExtension)base.Extension;
48 |
49 | public override bool IsDatabaseProvider => false;
50 |
51 | public override int GetServiceProviderHashCode() => 0;
52 |
53 | public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other)
54 | => other is ExtensionInfo;
55 |
56 | public override void PopulateDebugInfo(IDictionary debugInfo)
57 | => debugInfo["InMemory:" + nameof(InMemoryHierarchyIdDbContextOptionsBuilderExtensions.UseHierarchyId)] = "1";
58 |
59 | public override string LogFragment => "using HierarchyId ";
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Microsoft.EntityFrameworkCore.InMemory.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.EntityFrameworkCore.InMemory.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to UseHierarchyId requires AddEntityFrameworkInMemoryHierarchyId to be called on the internal service provider used..
65 | ///
66 | internal static string ServicesMissing {
67 | get {
68 | return ResourceManager.GetString("ServicesMissing", resourceCulture);
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | UseHierarchyId requires AddEntityFrameworkInMemoryHierarchyId to be called on the internal service provider used.
122 |
123 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId/Storage/InMemoryHierarchyIdTypeMapping.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.EntityFrameworkCore.ChangeTracking;
3 | using Microsoft.EntityFrameworkCore.Storage;
4 | using Microsoft.EntityFrameworkCore.Storage.Json;
5 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6 |
7 | namespace Microsoft.EntityFrameworkCore.InMemory.Storage
8 | {
9 | internal class InMemoryHierarchyIdTypeMapping : CoreTypeMapping
10 | {
11 | public InMemoryHierarchyIdTypeMapping(Type clrType)
12 | : base(new CoreTypeMappingParameters(clrType))
13 | {
14 | }
15 |
16 | private InMemoryHierarchyIdTypeMapping(CoreTypeMappingParameters parameters)
17 | : base(parameters)
18 | {
19 | }
20 |
21 | public override CoreTypeMapping WithComposedConverter(
22 | ValueConverter converter,
23 | ValueComparer comparer = null,
24 | ValueComparer keyComparer = null,
25 | CoreTypeMapping elementMapping = null,
26 | JsonValueReaderWriter jsonValueReaderWriter = null)
27 | => new InMemoryHierarchyIdTypeMapping(
28 | Parameters.WithComposedConverter(
29 | converter,
30 | comparer,
31 | keyComparer,
32 | elementMapping,
33 | jsonValueReaderWriter));
34 |
35 | protected override CoreTypeMapping Clone(CoreTypeMappingParameters parameters)
36 | => new InMemoryHierarchyIdTypeMapping(parameters);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/EFCore.InMemory.HierarchyId/Storage/InMemoryHierarchyIdTypeMappingSourcePlugin.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Storage;
2 |
3 | namespace Microsoft.EntityFrameworkCore.InMemory.Storage
4 | {
5 | internal class InMemoryHierarchyIdTypeMappingSourcePlugin : ITypeMappingSourcePlugin
6 | {
7 | public CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
8 | {
9 | var clrType = mappingInfo.ClrType;
10 |
11 | return typeof(HierarchyId).IsAssignableFrom(clrType)
12 | ? new InMemoryHierarchyIdTypeMapping(clrType)
13 | : null;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/EFCore.SqlServer.HierarchyId.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.1.31903.286
5 | MinimumVisualStudioVersion = 15.0.26124.0
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.InMemory.HierarchyId", "EFCore.InMemory.HierarchyId\EFCore.InMemory.HierarchyId.csproj", "{5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.InMemory.HierarchyId.Test", "EFCore.InMemory.HierarchyId.Test\EFCore.InMemory.HierarchyId.Test.csproj", "{F6B7191A-CA56-4D3B-BBEE-10334DED46E9}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|x64 = Debug|x64
14 | Debug|x86 = Debug|x86
15 | Release|Any CPU = Release|Any CPU
16 | Release|x64 = Release|x64
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Debug|x64.ActiveCfg = Debug|Any CPU
23 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Debug|x64.Build.0 = Debug|Any CPU
24 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Debug|x86.ActiveCfg = Debug|Any CPU
25 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Debug|x86.Build.0 = Debug|Any CPU
26 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Release|x64.ActiveCfg = Release|Any CPU
29 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Release|x64.Build.0 = Release|Any CPU
30 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Release|x86.ActiveCfg = Release|Any CPU
31 | {5CFC3CC1-57FA-4CC5-BC1B-8E868072FD9E}.Release|x86.Build.0 = Release|Any CPU
32 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Debug|x64.ActiveCfg = Debug|Any CPU
35 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Debug|x64.Build.0 = Debug|Any CPU
36 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Debug|x86.ActiveCfg = Debug|Any CPU
37 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Debug|x86.Build.0 = Debug|Any CPU
38 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Release|x64.ActiveCfg = Release|Any CPU
41 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Release|x64.Build.0 = Release|Any CPU
42 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Release|x86.ActiveCfg = Release|Any CPU
43 | {F6B7191A-CA56-4D3B-BBEE-10334DED46E9}.Release|x86.Build.0 = Release|Any CPU
44 | EndGlobalSection
45 | GlobalSection(SolutionProperties) = preSolution
46 | HideSolutionNode = FALSE
47 | EndGlobalSection
48 | GlobalSection(ExtensibilityGlobals) = postSolution
49 | SolutionGuid = {C4BE52ED-57A8-4637-BC54-0934E9A46112}
50 | EndGlobalSection
51 | EndGlobal
52 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Brice Lambson, et al.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | EntityFrameworkCore.SqlServer.HierarchyId
2 | ========================================
3 |
4 |  [](https://www.nuget.org/packages/EntityFrameworkCore.SqlServer.HierarchyId) [](https://www.nuget.org/packages/EntityFrameworkCore.SqlServer.HierarchyId) 
5 |
6 | Adds hierarchyid support to the SQL Server EF Core provider.
7 |
8 | ⚠️ Moved to EF Core
9 | ------------------
10 |
11 | This project has been merged into [dotnet/efcore](https://github.com/dotnet/efcore). All future bug fixes, enhancements, and releases will be done as part of the main EF Core project.
12 |
13 | Installation
14 | ------------
15 |
16 | The latest stable version is available on [NuGet](https://www.nuget.org/packages/EntityFrameworkCore.SqlServer.HierarchyId).
17 |
18 | ```sh
19 | dotnet add package EntityFrameworkCore.SqlServer.HierarchyId
20 | ```
21 |
22 | Compatibility
23 | -------------
24 |
25 | The following table show which version of this library to use with which version of EF Core.
26 |
27 | | EF Core | Version to use |
28 | | ------- | --------------- |
29 | | 7.0 | 4.x |
30 | | 6.0 | 3.x |
31 | | 3.1 | 1.x |
32 |
33 | Usage
34 | -----
35 |
36 | Enable hierarchyid support by calling UseHierarchyId inside UseSqlServer. UseSqlServer is is typically called inside `Startup.ConfigureServices` or `OnConfiguring` of your DbContext type.
37 |
38 | ```cs
39 | options.UseSqlServer(
40 | connectionString,
41 | x => x.UseHierarchyId());
42 | ```
43 |
44 | Add `HierarchyId` properties to your entity types.
45 |
46 | ```cs
47 | class Patriarch
48 | {
49 | public HierarchyId Id { get; set; }
50 | public string Name { get; set; }
51 | }
52 | ```
53 |
54 | Insert data.
55 |
56 | ```cs
57 | dbContext.AddRange(
58 | new Patriarch { Id = HierarchyId.GetRoot(), Name = "Abraham" },
59 | new Patriarch { Id = HierarchyId.Parse("/1/"), Name = "Isaac" },
60 | new Patriarch { Id = HierarchyId.Parse("/1/1/"), Name = "Jacob" });
61 | dbContext.SaveChanges();
62 | ```
63 |
64 | Query.
65 |
66 | ```cs
67 | var thirdGeneration = from p in dbContext.Patriarchs
68 | where p.Id.GetLevel() == 2
69 | select p;
70 | ```
71 |
72 | Testing
73 | -------
74 | A package for the In-Memory EF Core provider is also available to enable unit testing components that consume HierarchyId data.
75 |
76 | ```sh
77 | dotnet add package EntityFrameworkCore.InMemory.HierarchyId
78 | ```
79 |
80 | ```cs
81 | options.UseInMemoryDatabase(
82 | databaseName,
83 | x => x.UseHierarchyId());
84 | ```
85 |
86 | See also
87 | --------
88 |
89 | * [Hierarchical Data (SQL Server)](https://docs.microsoft.com/sql/relational-databases/hierarchical-data-sql-server)
90 | * [Entity Framework documentation](https://docs.microsoft.com/ef/)
91 |
--------------------------------------------------------------------------------
/key.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/efcore/EFCore.SqlServer.HierarchyId/28b9454acb7c001646bd8c5e4bf435ae6d990026/key.snk
--------------------------------------------------------------------------------