I’m trying to create a generic value converter for strongly typed ids in ef core so i don’t create coverter for every strongly typed id that i have but i don’t now how to initialize it when i get the value from the database
public interface EntityId {
Guid Identifier { get; init; }
}
public record MoveId(Guid Identifier) : EntityId;
var converter = new EntityIdConverter<MovieId>();
builder
.Property(movie => movie.Id)
.HasConversion(converter);
public class EntityIdConverter<TId> : ValueConverter<TId, Guid>
where TId : EntityId
{
public EntityIdConverter()
: base(
id => id.Identifier,
value => new EntityId(value) // How to initialize id record without using Activator or reflection?
)
{
}
}