Skip to content

New feature: EF Core Value Generators #920

Description

@epicoxymoron

Describe the feature

I'd love to be able to have value generators generated by Vogen for my Guid-based primary keys in EF. The wiki clearly shows how you could (unsafely) create value generators for an int type, but Guid types can be generated safely, and it save a lot of boilerplate of Vogen could do this for me.

I'd propose that when the underlying type is a Guid AND the author has enabled the EfCoreConverter, then a value generator is constructed as follows:

// this is the triggering struct
[ValueObject<Guid>(Conversions.Default | Conversions.EfCoreValueConverter)]
public partial struct MyId;

// this is the generated class
public class MyIdValueGenerator : ValueGenerator<MyId>
{
    public override bool GeneratesTemporaryValues => false;
    public override MyId Next(EntityEntry entry) => MyId.From(Guid.NewGuid());
}

I'm happy to try to build it, if it's an idea you would accept into the project. I'm open to other triggers, that's just the most logical one that comes to mind.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions