-
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
Improve exception message when reconfiguring an owned type #27705
Comments
@DanielDudda I am not able to reproduce this. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. |
@ajcvickers thanks for looking at it. I've reduced the original project's code to only contain the required parts to show this bug. I've already run the dotnet ef migration command and still the properties are set as longtext. Here's a link. I'm using docker compose to run the MariaDB server instance and connect to the .net project. Maybe it has something to do with it or some configurations I've set? |
@ddudda174 Given that GitHub repo, what are the steps to reproduce what you are seeing? (I get unrelated errors attempting to start the app.) |
@ajcvickers Given the current state of the GitHub repo I would do the following steps to reproduce it (nothing special here):
I'm currently using JetBrains Rider IDE with the Entity Framework Core UI Plugin, which simply provides a more convenient way to call the dotnet ef-core commands and filling parameters like "-project *.csproj" for me. Also tried using the Package Manager Console and the "Add-Migration " command inside Visual Studio 2022, same result. Just noticed that the max-length value for the custom-id I'm using is correct. I've configured it via the "ConfigureConventions" method, but configuring the max-length inside the EntityTypeConfiguration class has no effect. protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder.Properties<DbId>()
.HaveConversion<DbIdConverter>()
.HaveMaxLength(DbId.MAX_LENGTH);
} (What errors do you receive, maybe we can fix 'em?) |
@ddudda174 Does that bad model get created when you run the application, or only when you create the migration? |
@ajcvickers what do you mean by bad model? The entity PersonalData was created by me, and setup inside the UserConfig class with OwnsOne. After that I run the ef core command (e.g. Add-Migration TestOwnedTypeConfig) to generate the migration file which comes up with the longtext column types instead of for example varchar(64) for property "FirstName". When I simply run the app(without creating a migration and running Update-Database) then it will cause exceptions which lead to "the database does not fit the current model" error message. Am i missing something here? I've also deleted everything and started from scratch to generate a new snaptshot class, but without success. As a side note, this was also a former .NET 5 project that was upgraded to latest .NET 6 versions including nuget packages. |
@ddudda174 The issue here is that the code is configuring |
@ajcvickers Just saw that owned types should be seeded after a
At least I could unveal a probably real bug :D |
Note for triage: we should look at the working of the owned and non-owned message, since Ignore is very rarely the way to solve this.
I doubt we will fix this, since it requires a completely invalid configuration in order to get into this situation. |
@ajcvickers you can close this issue if you want (or keep it open for the non-owned message rework), I fixed the configuration and it's now working. Thanks for your help! Just one more question: Is it ok to use |
It seems like the configuration (Fluent API) for an Owned type entity is ignored. I've change the configuration for the
UserData
entity from normal (User and UserData had their own configs) to owned type (now owned by User entity).Strangely it's now changing all columntypes and some other stuff which was configured correctly before to "longtext" and also ignoring additional attributes like non-nullable (
IsRequired()
).I couldn't find helpful solutions and tried different ways (except Attributes inside the class) without luck. Am I missing something here?
EF Core entity configuration inside
User
entityEF Core created migration script (copy&paste of related parts)
EF Core version: 6.0.3 (latest)
Database provider: Pomelo.EntityFrameworkCore.MySql (latest)
Target framework: .NET 6.0
Operating system: Wndows 11
IDE: JetBrains Rider 2021.3.3 or VS 2022 17.1.2 (doesn't matter)
The text was updated successfully, but these errors were encountered: