EF Core HasPrecision()

Has anyone ever defined precision for decimal numbers in EF Core without using attributes? Even defining the value for some reason is truncated at "decimal(18,2)" when I do the migrations.
10 Replies
Samuel Duarte
Samuel DuarteOP8mo ago
builder
.Property(transfer => transfer.Amount)
.HasColumnType("decimal")
.HasPrecision(14, 2);

# Migrations code generated

Amount = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
builder
.Property(transfer => transfer.Amount)
.HasColumnType("decimal")
.HasPrecision(14, 2);

# Migrations code generated

Amount = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
leowest
leowest8mo ago
No description
leowest
leowest8mo ago
worked for me using postgresql
leowest
leowest8mo ago
No description
Jimmacle
Jimmacle8mo ago
you can also specify the column type directly as decimal(x,y)
leowest
leowest8mo ago
I didn't even need to specify the columntype on my first try efcore automagically did its work I wonder if his issue is a version/db issue
Samuel Duarte
Samuel DuarteOP8mo ago
I used SqlServer and still the precision is not defined
leowest
leowest8mo ago
and what is the version of the efcore nuget you're using?
Samuel Duarte
Samuel DuarteOP8mo ago
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
leowest
leowest8mo ago
yeah I cannot reproduce it sorry maybe some one else knows about it
Want results from more Discord servers?
Add your server