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 Duarte3mo 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
leowest3mo ago
No description
leowest
leowest3mo ago
worked for me using postgresql
leowest
leowest3mo ago
No description
Jimmacle
Jimmacle3mo ago
you can also specify the column type directly as decimal(x,y)
leowest
leowest3mo 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 Duarte3mo ago
I used SqlServer and still the precision is not defined
leowest
leowest3mo ago
and what is the version of the efcore nuget you're using?
Samuel Duarte
Samuel Duarte3mo 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
leowest3mo ago
yeah I cannot reproduce it sorry maybe some one else knows about it