-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow mapping string to PG ltree, not just the .NET LTree type (which is supported via value conversion, as the ADO layer only supports string). This also resolves issues in seeding. Fixes #1929
- Loading branch information
Showing
4 changed files
with
79 additions
and
43 deletions.
There are no files selected for viewing
29 changes: 0 additions & 29 deletions
29
src/EFCore.PG/Storage/Internal/Mapping/LTreeTypeMapping.cs
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
src/EFCore.PG/Storage/Internal/Mapping/NpgsqlLTreeTypeMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
using NpgsqlTypes; | ||
|
||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping | ||
{ | ||
public class NpgsqlLTreeTypeMapping : NpgsqlStringTypeMapping | ||
{ | ||
private static readonly ConstructorInfo Constructor = typeof(LTree).GetConstructor(new[] { typeof(string) })!; | ||
|
||
public NpgsqlLTreeTypeMapping() | ||
: base( | ||
new RelationalTypeMappingParameters( | ||
new CoreTypeMappingParameters( | ||
typeof(LTree), | ||
new ValueConverter<LTree, string>(l => l, s => new(s))), | ||
"ltree"), | ||
NpgsqlDbType.LTree) | ||
{ | ||
} | ||
|
||
protected NpgsqlLTreeTypeMapping(RelationalTypeMappingParameters parameters) | ||
: base(parameters, NpgsqlDbType.LTree) | ||
{ | ||
} | ||
|
||
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters) | ||
=> new NpgsqlLTreeTypeMapping(parameters); | ||
|
||
public override Expression GenerateCodeLiteral(object value) | ||
=> Expression.New(Constructor, Expression.Constant((string)(LTree)value, typeof(string))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters