Fix table metadata collection for keyless entities#77
Merged
PhenX merged 2 commits intoPhenX:mainfrom Oct 30, 2025
Merged
Conversation
Owner
|
Thanks for your contribution, I have no doubt it fixes the issue, but can you add a keyless entity in the test DbContext please, to be sure the issue won't come back ? |
Contributor
Author
Hey! Thanks for the feedback. I added the entity to the context. Without the fix, the tests fail now, but with my fix they run fine. Although I don't use the entity for anything in the tests so far. Is that okay for you like that? |
PhenX
approved these changes
Oct 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have an EF Core application with a keyless (
[Keyless]annotation) entry that represents a database view. When trying to useBulkInsert, I always get this error, regardless of what entity type I'm trying to insert:This seems to be caused in
GetTables, which tries to createTableMetadatas for all entity types. However, when any of these entity types don't have an associated table name, theTableMetadataconstructor will throw the aboveSystem.InvalidOperationException: Cannot determine table name.. This is the case for the keyless entity in our codebase,GetTableNamereturns null here.This seems to be fixable by simply filtering out entities where the table name is null. I tried it for our usecase, and it seems to work, although I don't know whether this has any repercussions on the rest of the library, although I hope it doesn't, because keyless entities can't ever be inserted anyway, so it shouldn't be relevant for the lib. See https://learn.microsoft.com/en-us/ef/core/modeling/keyless-entity-types