-
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
Owned Type is generating error for missing a primary key #10814
Comments
@FrederickBrier Can you post code for the entity type and owned entity type and the code in OnModelCreating that configures the owned type? |
My problem was that I was using EF Core 2.0.3. An OwnedAttribute (Annotation) was added on 2017-12-14 in a commit by AndriySvyryd. It does not seem to exist in 2.0.3. I did not see the tag for 2.0.3, but 2.0.2 was tagged 2017-10-13. So I switched to 2.1.0-preview1-28181 off of dotnet.myget.org and now am getting the exception described in both: Support cascade updates for owned types/aggregates #10551 The annotation only occurs once in the DataAnnotationTestBase.cs file, although obviously it is used in many tests. My entities are very similar and simple, except the classes are public, not protected. If you have any suggestions on debugging this problem, please let me know. This owned types functionality was announced, so I assume it is real, works, and the problem is my use of it. Thank you. |
@FrederickBrier Owned types were released in EF Core 2.0, but with some limitations. At that time, configuration was through the fluent API only. OwnedAttribute has been added for EF Core 2.1, which is as of now only available in nightly builds. If you think you are hitting a bug, then we will most likely be able to help if you post a runnable project/solution or code listing that demonstrates the issue. If you are asking how to use the feature, then documentation is being worked on in this PR: dotnet/EntityFramework.Docs#469 |
It is now working with the preview release. Thank you! |
I created an owned type class and included it as a property within a class mapped to a database. I added two DataAnnotations to each of the 3 properties within the owned type class.
EF Core is assuming that because there are DataAnnotations, that the owned class is a full table class. It then throws an exception about requiring a primary key - which makes sense. It seems like there needs to be an [OwnedType] DataAnnotation.
Do I have to put the Owned Type in the same source file, as per your examples?
Further technical details
EF Core version: 2.0.3
Database Provider: For the test which is failing SQLite (memory). For the App, not yet there - PostgreSQL.
Operating system: Windows 10 Pro
IDE: Visual Studio 2017 15.4
The text was updated successfully, but these errors were encountered: