Skip to content
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

adding a double to the model breaks #2

Open
mark-cb opened this issue Mar 9, 2022 · 3 comments
Open

adding a double to the model breaks #2

mark-cb opened this issue Mar 9, 2022 · 3 comments

Comments

@mark-cb
Copy link

mark-cb commented Mar 9, 2022

Hi and thanks for the example.

I have simply updated the model so that price is now a double, as below. However the app simply crashes. Any ideas?

Cheers

public sealed class Car
{
public int Id { get; set; }
public string Brand { get; set; }
public double Price { get; set; }
}

@TrevorDArcyEvans
Copy link
Owner

Not sure but you may have to run a schema update

@mark-cb
Copy link
Author

mark-cb commented Apr 25, 2022

Issue has now been raised with the dotnet/runtime.

@matt-andrews
Copy link

For those running into this issue, it can be solved with a value converter on double/decimal.

class DoubleConverter : ValueConverter<double, string>
{
    public DoubleConverter() : base(Serialize, Deserialize, null) { }
    private static Expression<Func<string, double>> Deserialize => x => double.Parse(x);
    private static Expression<Func<double, string>> Serialize => x => x.ToString();
}

In your DbContext:

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
    configurationBuilder.Properties<double>().HaveConversion<DoubleConverter>();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants