Our type mapping supports precision and scale. We should add back EF6's HasPrecision() method on PropertyBuilder.
Any ETA on this feature? Or any way to do it in a database agnostic way currently? Having to tie up model creation to a particular database solely because of this missing piece is quite annoying.
Is this gonna be shipped in 2.2.+?
@whizkidwwe1217 If you mean in a patch of 2.2, then no. If you mean in 3.0 or later, then that is the plan.
Note to implementer: Don't forget to...
SQL Server notes:
Data type | Default precision | Default scale
--- | ---:| ---:
datetime2 | 7 | (n/a)
datetimeoffset | 7 | (n/a)
decimal | 18 | 0
float | 53 | (n/a)
numeric | 18 | 0
time | (n/a) | 7
how to use it in "netcoreapp2.2"?
I think they're planning to implement it in 3.0 but we really need this in 2.2. @ajcvickers @bricelam
You can always specify full type using HasColumnType. This would be a good sugar to add but not a blocker in any sense.
@bricelam I am interested in working on it, Will you be able to provide more implementation details?
Look at the IsUnicode or HasMaxLength code for an end-to-end example
And yes, feel free to open a draft PR if you get stuck or have implementation questions
@SARAVANA1501 RelationalTypeMappingSource should also be updated to account for this.
@dotnet/efcore Throughout a lot of the current code precision and scale are treated as ints. But EF6's HasPrecision(precision, scale) treated them as bytes. and so does DbParameter.
Should I update all our code to use byte or simply cast to byte when I need a DbParameter? My preference is the former but wanted to make sure because it's in a lot of places.
@lajones This API is defined in Core, so DbParameter isn't that relevant. We usually stick to int unless there's a good reason not to even if the value will never be larger than Byte.Max
@AndriySvyryd I'm updating SqlServerDecimalTypeMapping.ConfigureParameter to include precision and scale. Currently Precision.Value is an int?, but parameter.Precision requires a byte.
Provider implementation should cast as needed.
OK. Will do.
@dotnet/efcore Also would like opinion on what effect HasPrecision(precision) with no scale specified should have on the scale.
SqlServerDecimalTypeMapping's default for a decimal property is decimal(18,2), in particular note that the scale is 2. If I then call e.g. HasPrecision(4) on that property, i.e. I do not specify the scale, should I expect the scale to remain unchanged at 2 or should it change to 0? If you define a column in SqlServer as decimal(4) you expect the precision to be 4 and the scale to be 0, i.e. any time I call just HasPrecision(precision) with no scale then the scale is set to 0. But remember HasPrecision() applies to all providers, not just SqlServer.
Most helpful comment
@whizkidwwe1217 If you mean in a patch of 2.2, then no. If you mean in 3.0 or later, then that is the plan.