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

modelBuilder.Model.GetEntityTypes() returns an unexpected List<List<string>> Keyless entry after migrating to .NET 6 #28556

Closed
databrecht opened this issue Aug 1, 2022 · 2 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@databrecht
Copy link

Include your code

In order to offset indices for tests (which makes it more foolproof when incremental indices by accident exist yet point to a different type but the motivation is not that important) we have code that loops over the Entity Types.

foreach (var entityType in modelBuilder.Model.GetEntityTypes())
  {
      if (!ignored.Any(ign => entityType.Name.Contains(ign)))
      {
              method.MakeGenericMethod(entityType.ClrType).Invoke(null, new object[] { modelBuilder });
      }
  }

When moving to Dotnet6, we moved to to the following EF core version <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.7" /> and noticed that there is a surprising entry in the result from 'GetEntityTypes'. Next to our models it now contains EntityType: List<List<string>> Keyless which does not satisfy our type constraints of the function we are calling. We can easily fix this code but I'm assuming you might want to be aware of it so decided to log it here. My apologies if this is intended behaviour.

Include stack traces

Stack trace is mainly our code so it won't help you and includes client details, the error is:

  Error Message:
   System.ArgumentException : GenericArguments[0], 'System.Collections.Generic.List`1[System.Collections.Generic.List`1[System.String]]', on 'Void Configure[TEntity](Microsoft.EntityFrameworkCore.ModelBuilder)' violates the constraint of type 'TEntity'.
---- System.Security.VerificationException : Method MraApi.Util.BaseEntityConfiguration.Configure: type argument 'System.Collections.Generic.List`1[System.Collections.Generic.List`1[System.String]]' violates the constraint of type parameter 'TEntity'.

Include provider and version information

EF Core version:6.0.7
Database provider: npgsql
Target framework: NET 6.0
Operating system: Manjaro
IDE: Rider

@ajcvickers
Copy link
Member

@databrecht The model available while OnModelCreating is being run may not be the final model, since various conventions run while the model is being built and when it is finalized. This means the model during OnModelCreating can have configurations for types that don't end up as entity types in the final model.

#214, which is planned for 7.0, will allow greater access to the conventions, potentially providing a better method for what you are trying to do.

@databrecht
Copy link
Author

Thanks for the explanation, then what I logged was not a bug 👍

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label Aug 1, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

2 participants