-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET 5.0 RC1 p.SetColumnType("[money]") results in wrong type in migration #22569
Comments
@henrikdahl8240 Using square brackets around type names is not something that EF Core expects, and hence EF doesn't recognize Is there a reason you're specifying type names in this way? |
@ajcvickers OK, so I will remove the brackets. I thought that the argument is forwarded as is to SQL Server and if you try to use the context menu in SQL Server Management Studio for a database and select Tasks => Generate Scripts ..., types appear with brackets around in line with the usual reasons for using brackets when using SQL Server. Therefore I put the brackets around, like e.g. [money]. |
@henrikdahl8240 We'll discuss. |
I think there should be made a clear decision on the nature/syntax of the actual argument and the documentation should be clear, so you have no doubt as you use the feature. |
@henrikdahl8240 That's reasonable, although in my 12+ years on EF I think this is the first time I have ever seen anyone use square brackets in this API. |
I also have this construction in my code: As far as I remember, it does not work withoug brackets, but only with brackets, at least in some of the .NET 5.0 previews and therefore I have consistently put brackets around the type lexemes. |
Fixes #22569 In EF Core 3.1, it was possible to specify a SQL Server column type using square brackets. For example, "[money]" instead of "money". EF Core didn't understand this, so we treated it as an unknown decimal type, and passed it through to SQL Server as-is. In EF Core 5.0, we added support for precision and scale specified independently of the type. We don't do this when we know the type is `money` because doing so is not valid. However, since we don't recognize "[money]" it gets precision and scale added. The fix is to recognize SQL Server types with square brackets. Note that only type names without spaces can have square brackets.
If you have a property of type
decimal
and dop.SetColumnType("[money]")
using .NET 5.0 RC1 the migration will specify another type, because it will specify[money](18,2)
.Money however neither has precision nor scale, so it fails when updating the database.
If you manually substitute "
[money](18,2)
" => "[money]
" as you actually specified usingp.SetColumnType("[money]")
, it works fine.The text was updated successfully, but these errors were encountered: