Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add an option to generate a Guid primary key value on the entity class #549

Open
ArnaudB88 opened this issue Mar 22, 2024 · 0 comments · May be fixed by #550
Open

[Feature] Add an option to generate a Guid primary key value on the entity class #549

ArnaudB88 opened this issue Mar 22, 2024 · 0 comments · May be fixed by #550

Comments

@ArnaudB88
Copy link

In our company, we use your generator for many years now with many developers. Over the years, we added some features so it works better with our solutions. As a sign of appreciation, I want to suggest some features because I think it will help some other developers as well.

Feature description:

Add an option to generate a new Guid value for the primary key property in the generated entity classes.

Feature motivation & example usage:

This allows using the primary key property before changes are saved on the dbContext.
We use the CQRS pattern with MediatR and database changes are saved automatically in the 'code pipeline'. When we have functionality which add for example a 'Project' entity, we also return the Id of the created entity to the requester (in our case we return it as a web api result). We contruct the response before database changes are done, so we already need the Id. This feature allows us to use the Id before the 'database save changes'.

Another example: when adding entities, this feature allows using the Id of the 'entities to be added' for other method calls. Sometimes we are not allowed to pass entities to other layers of the application (by architectural guidelines, seperation of concern). But the primary key value (Guid), is allowed to be passed as a value. This feature allows using the already generated value.

The option is a boolean, true enables the feature.

YAML usage:

data:
  entity:
    generatePkValue: true

Code generation result:

using System;
using System.Collections.Generic;

namespace Company.Project.Domain.Entities;

public partial class Project
{
    public Project()
    {
        #region Generated Constructor
        Id = Guid.NewGuid();
        #endregion
    }

    #region Generated Properties
    public Guid Id { get; set; }
    #endregion
}

Please review the feature request and evaluate if you think this is an addition to your repo.
(pull request will be added)

Thanks

ArnaudB88 pushed a commit to ArnaudB88/EntityFrameworkCore.Generator that referenced this issue Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant