How to format decimal numbers using Fluent API in the Entity Framework?

Asked

Viewed 121 times

1

How to create a formatting with precision 10,4 (4 decimal places) to save decimal data to SQL Server? This format description goes inside the modelBuilder, however, I have not found any code already defined to do this formatting.

2 answers

2


  • Thank you, George. The solution is this. However, an error appears, identified exactly in the reserved word ". Hasprecision". The following error is: "Error: CS1061 - ?Propertybuilder<double>' does not contain a definition for "Hasprecision" and it was not possible to find any "Hasprecision" extension method that accepts a first argument of type ːPropertybuilder<double>' ". Would you know what it’s about?

  • @Victormoraes Change your field to decimal type to use precision. It’s like double.

  • I already changed there in the domain and keeps showing the error.

2

If you need to set a decimal property, use:

        modelBuilder.Entity<Class>(entity =>
{
            entity.Property(e => e.PropertyName)
            .HasColumnType("decimal(10,2)");
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.