How to implement the field decimal(5,2)
in EntityFrameworkCore 1.0 rc2
?
HasPrecision
seems to be not available anymore?
I'm seeing some examples like this:
entityBuilder.Property(r => r.TotalScore)
.HasColumnType("decimal(5,2)")
.IsRequired(true);
and the code to support this is here, so hopefully this is supported in the version you're using:
You can add extensions for that like this:
public static class SqlServerModelBuilderExtensions
{
public static PropertyBuilder<decimal?> HasPrecision(this PropertyBuilder<decimal?> builder, int precision, int scale)
{
return builder.HasColumnType($"decimal({precision},{scale})");
}
public static PropertyBuilder<decimal> HasPrecision(this PropertyBuilder<decimal> builder, int precision, int scale)
{
return builder.HasColumnType($"decimal({precision},{scale})");
}
}