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

RewriteName Errors With Views That Has Keys #279

Open
mattmentrup opened this issue May 24, 2024 · 3 comments
Open

RewriteName Errors With Views That Has Keys #279

mattmentrup opened this issue May 24, 2024 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@mattmentrup
Copy link

Core 6
Oracle.EntityFrameworkCore 6
EFCore.NamingConvention, Latest on NuGet.org

Naming Convention Used:
UsedSnakeCaseNamingConvetion,
UseUpperSnakeCaseNamingConvention

During the OnModelCreating(ModelBuilder), when configuring the modelBuilder with a View and that view has keys defined, the RewriteName function throws an 'object reference not set to an instance of an object' error.

OnModelCreating(builder) {
  builder.EnsureSchema("abc"); // I do not believe this matters, but just in case for testing.

  builder.Entity<DTOEntity>(ef => {
    ef.ToView("xyz");
    ef.HasKey(e => new { e.Key1, e.Key2 }); // Throws error on this line.
  }
}

Interestingly enough, when declaring the ToView after the HasKey method, the error above is not thrown.

For example, the below snippet does not cause the error to occur.

OnModelCreating(builder) {
  builder.EnsureSchema("abc"); // I do not believe this matters, but just in case for testing.

  builder.Entity<DTOEntity>(ef => {
    ef.HasKey(e => new { e.Key1, e.Key2 });
    ef.ToView("xyz");
    // No error is thrown and the extension is happy.
  }
}
@mattmentrup
Copy link
Author

mattmentrup commented May 25, 2024

I identified the issue that Microsoft EntityFramework will set the Name value for the key after the entity has been declared as a view to null.

I submitted a PR #280 to handle this fix by adjusting the INameRewriter.RewriteName signature to accept the nullable string value and can return a nullable string value.

@roji
Copy link
Member

roji commented May 25, 2024

@mattmentrup thanks.. I'm very busy right now with other priorities - I traditionally turn my attention to this plugin close to the release time in November, when other components are already frozen etc. Just to set expectations in terms of reviewing etc - but I'll definitely take a look later in the year.

@roji roji added this to the 9.0.0 milestone May 25, 2024
@roji roji added the bug Something isn't working label May 25, 2024
@mattmentrup
Copy link
Author

Not a problem, thanks for maintaining this plugin. Solved my issue with naming schemas for oracle at work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants