-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Configuring a value converter for a property of an owned type #13485
Comments
think you need Entity<MyEntity>().Property(e => e.Price.Currency).HasConversion |
@Tarig0 I'd be really surprised if that works. Did you try it? |
@BrightSoul This should work: modelBuilder.Entity<Blog>(c =>
{
c.OwnsOne(e => e.Price, b =>
{
b.Property(e => e.Currency).HasConversion<string>();
});
}); |
Thank you @ajcvickers, it's working wonderfully. I have to repeat that configuration with each usage of the Money type but it's not a big deal right now. Of course, a type-wide converter configuration would be even more useful. Something like this:
Also, I couldn't find any mention in the documentation, maybe a paragraph about owned types would help. |
@BrightSoul I'll file a docs issue. Global config of a converter is tracked by #10784. |
Hi all, I'using EF Core 2.1 and I have this value object in my model, which is then configured as an owned type for properties such as "Price".
Currency is a simple enum like this.
I'd like to persist the Currency property as a string, i.e. I want 'EUR' or 'USD' to appear in the database instead of its numerical representation.
For this, I tried to configure the
EnumToStringConverter
but the fluent interface doesn't seem to allow that. Things I've tried.How should I do it? I don't want to write a converter for the whole Money object.
Thanks in advance.
The text was updated successfully, but these errors were encountered: