-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
'CollectionOwnershipBuilder' does not contain a definition for 'HasAlternateKey' #15698
Comments
Of course, all of 5 minutes after I wrote this up and posted it, I discovered why this was happening, but I still think it should be attributed to buggy behavior. Shouldn't use the two attributes on the key in the Owned entity. Putting [Key] and [DatabaseGenerated] on the Id introduces this issue for each owned entity you add them to. Instead, of simply building a migration that can't be used, I'd instead expect to see the migration creation fail indicating that you can't use the Key attribute on OwnsMany subjects (maybe yet) and that the key(s) in the relationship should only be specified in OnModelBuilder. |
Describe what is not working as expected.
I've got several DbContexts in my solution. All are working as expected except for one, which is generating anomalous code in the snapshot and designer classes. I have an entity, let's call it ABC. ABC has a list of DEFs. DEF is marked as
[Owned]
and I have it configured as an OwnsMany in the OnModelCreating as in the following:The IDs for each are GUIDs, in case that's relevant. When I run the Add-Migration command, I use the following:
Add-Migration Initial -StartupProject SampleBuilder -Project Data.Abc -Verbose
This runs without issue and produces _Initial.cs, _Initial.Designer.cs and MyContextModelSnapshot. There is nothing flagged as wrong in _Initial.cs, but when looking at _Initial.Designer.cs, I see the following (names changed, of course):
I see exactly the same thing in the MyContextModelSnapshot.cs file and the same error.
I attempted to remove the migration and that worked fine. I re-added it and the same thing happened. It only occurs in that one spot and I haven't experienced this in any of the other many owned types in this or other DbContexts.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Here are the classes and their relevant bits:
Further technical details
EF Core version: 2.2.4
Microsoft.EntityFrameworkCore.Design: 2.2.4
Database Provider: Microsoft.EntityFrameworkCore.SqlServer: 2.2.4
Operating system: Windows 10 x64 Pro
IDE: Visual Studio 2019 Pro Stable channel, 16.0.3
The text was updated successfully, but these errors were encountered: