-
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
Using convertion for ValueObject will throw InvalidOperationException #10765
Comments
…e known Issue #10765 Because until the call to HasConversion is made we can't know whether or not the property can be mapped.
…e known Issue #10765 Because until the call to HasConversion is made we can't know whether or not the property can be mapped.
…e known Issue #10765 Because until the call to HasConversion is made we can't know whether or not the property can be mapped.
using 2.1.0-preview1-final; I found I had problems creating my context if I also Owned another property that was listed after the Conversion, i.e. order of the builder code is relevant But the following succeeds: Ta, G. |
@Devy-Devly Can you please file a new issue for this, including full details of how to reproduce the problem and version, etc. as requested in the issue template. |
Following the example of @glucaci , I am trying to convert a custom type Email to string with ValueConverter (Microsoft.EntityFrameworkCore 2.1.1):
it throw:
This issue is closed because #242 but... this is not working for me. |
Resolved, if I write:
modelBuilder.Ignore(); works fine! |
@manuelcaub what you actually need here is builder.OwnsOne(x => x.Email).HasConversion(
new ValueConverter<Email, string>(email => email, value => Email.Create(value))); The exception is because by convention EF Core recognizes every type you mention in You should use |
@manuelcaub Your code defines as DbSet for Emails: public DbSet<Email> Emails { get; set; } This tells EF that Email is an entity type, which is incorrect since it is in this case just a scalar property of another entity type. |
Steps to reproduce
Having the following model
and the configuration
it will throw:
Please feel free to change the name if it's not appropriate.
Further technical details
EF Core version: (2.1.0-preview1 local build with last commit bf03e18)
Database Provider: (Microsoft.EntityFrameworkCore.SqlServer 2.1.0-preview1 local build)
The text was updated successfully, but these errors were encountered: