-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add built-in support for parsable/formattable values for EF
Rather than adding explicit Ulid support as suggested in #18, a more flexible approach is to simply rely on the combination of IParsable<T> plus IFormattable checks on the TValue/TId and emit a standard EF value converter that relies on those, plus the INewable<TSelf> we already have for the struct-id itself. This involved a more flexible resource template selection mechanism, which needs further refactoring for simplification (and perhaps dropping altogether) of the BaseGenerator.
- Loading branch information
Showing
9 changed files
with
187 additions
and
73 deletions.
There are no files selected for viewing
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
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
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
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,34 @@ | ||
// <auto-generated /> | ||
#nullable enable | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
using StructId; | ||
|
||
[TStructId] | ||
file partial record struct TSelf(TValue Value) : INewable<TSelf, TValue> | ||
{ | ||
/// <summary> | ||
/// Provides value conversion for Entity Framework Core | ||
/// </summary> | ||
public partial class EntityFrameworkValueConverter : ValueConverter<TSelf, string> | ||
{ | ||
public EntityFrameworkValueConverter() : this(null) { } | ||
|
||
public EntityFrameworkValueConverter(ConverterMappingHints? mappingHints = null) | ||
: base(id => id.Value.ToString(null, null), value => TSelf.New(TValue.Parse(value, null)), mappingHints) { } | ||
} | ||
} | ||
|
||
file partial record struct TSelf | ||
{ | ||
public static TSelf New(TValue value) => throw new System.NotImplementedException(); | ||
} | ||
|
||
file partial struct TValue : IParsable<TValue>, IFormattable | ||
{ | ||
public static TValue Parse(string s, IFormatProvider? provider) => throw new NotImplementedException(); | ||
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out TValue result) => throw new NotImplementedException(); | ||
public string ToString(string? format, IFormatProvider? formatProvider) => throw new NotImplementedException(); | ||
} |
Oops, something went wrong.