Support for UUIDv7
Are there any plans to implement UUIDv7 as an Id type?
Not currently. But you could do this in your own app by creating your own template, as described in this post and this issue 🙂
Hi @andrewlock, I've decided to try creating a template using the Cysharp.Ulid and don't quite follow how to make it work.
When I write what I think I would need to create template and it does work. As you can see below I had to add IComparable to it as the abstract Entity class I used requires it for the typed id to be used as a generic parameter. Now I'm wondering if I need to make this more like the full version of a template because I see after the fact that I'm not getting a lot of functionality that the original templates provide. This does not produce the 350 lines of code that the built-in templates generate. I have another strongly typed id that uses the Int template and it generates a file that is 347 lines of code. So I lose a lot of functionality. Is using the full template the way to solve this?
Template:
partial struct PLACEHOLDERID : global::System.IComparable<PLACEHOLDERID>
{
public global::System.Ulid Value { get; }
public PLACEHOLDERID(global::System.Ulid value)
{
Value = value;
}
public int CompareTo(PLACEHOLDERID other)
{
return Value.CompareTo(other.Value);
}
public class EfCoreValueConverter
: global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter<PLACEHOLDERID, global::System.Ulid>
{
private static readonly global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints defaultHints
= new global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints(size: 16);
public EfCoreValueConverter() : this(null) { }
public EfCoreValueConverter(
global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null)
: base(
id => id.Value,
value => new PLACEHOLDERID(value),
defaultHints
)
{ }
}
}
Code produced by template: Notice the extra } at the end? I can't figure out why this is being added but it's not causing a compile error.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by the StronglyTypedId source generator
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
#pragma warning disable 1591 // publicly visible type or member must be documented
#nullable enable
namespace MarineEAM.Data.Models.WorkOrders
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("StronglyTypedId", "1.0.0-beta6")]
partial struct WorkOrderId : global::System.IComparable<WorkOrderId>
{
public global::System.Ulid Value { get; }
public WorkOrderId(global::System.Ulid value)
{
Value = value;
}
public int CompareTo(WorkOrderId other)
{
return Value.CompareTo(other.Value);
}
public class EfCoreValueConverter
: global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter<WorkOrderId, global::System.Ulid>
{
private static readonly global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints defaultHints
= new global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints(size: 16);
public EfCoreValueConverter() : this(null) { }
public EfCoreValueConverter(
global::Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints? mappingHints = null)
: base(
id => id.Value,
value => new WorkOrderId(value),
defaultHints
)
{ }
}
}
} // What is this doing here?
... This does not produce the 350 lines of code that the built-in templates generate
Correct, your template has to include everything you want - you could start from one of the built-in templates for example
Code produced by template: Notice the extra } at the end?
It's not "extra" the indenting is just a bit wonky 😄 The final } comes from the mespace MarineEAM.Data.Models.WorkOrders {
If you indent all your code in your template, it'll look pretty again 😄
Thank you, I appreciate your feedback
@andrewlock, I do have one more question. The templates that use the full name have both Dapper and EntityFramework dependencies. If I were to use the guid-full template and I did not have Dapper installed wouldn't the generated code fail with a build error?
Yes, it would😊 the same goes if you use some of the other converters or IDs that have external dependencies. This is where the templates come in, you can tailor what you need to your requirements 😊