Entity Framework 6 decimal precision

entity-framework-6

Question

I have a decimal number of 18,3 set in my SQL database for the Code-First Entity Framework. database item

public decimal? Kolhalt { get; set; }

OnModelCreating is where I have

     modelBuilder.Entity<Skada>().Property(o => o.Kolhalt).HasPrecision(18, 3);

The value is listed in the database as Kolhalt (decimal(18, 3), null).

When I insert or edit a value using EntityFramework, it retains three decimal places, but when I do so directly in the database, it is reduced to two.

I can observe that EF specifies two decimals for the saved value using SQL Server Profiler:

[Kolhalt] = @14 ...  @14 decimal(18,2) ...  @14=5.12

(The entered value was 5.123).

Therefore, when I use SaveChanges, EF truncates the information supplied to the database for some reason ().

Do I need to give the amount of decimals somewhere else for SaveChanges() to work properly?

Best regards, Henrik

1
2
5/30/2017 8:41:54 AM

Accepted Answer

ZZZ_tmp
4
5/30/2017 2:52:42 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow