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
Using Concat for model/seed data in migrations may truncate long strings #24112
Comments
/cc @bricelam |
My preliminary experimentation says things are not as straight-forward as in posts. |
Here is a nice explanation of the Data type precedence used: There is a workaround: Let's try: This returns only 4000 chars: This returns everything: (inspired here: https://sqlundercover.com/2017/09/27/concatenation-truncation-are-your-strings-being-truncated/) |
@saliksaly - I have gone through the official T-Sql documentation. My point is that regardless of issue happening due to data type precedence, same data type is applied for |
efcore/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs Lines 1911 to 1919 in 843e35b
Comments declare variable of type In order to fix this issue, we need to change the migration code to stop using string type mapping to print sql_variant literal else fix for this issue is generating invalid SQL for a working case of comments. cc: @bricelam |
/cc @bricelam |
Hello @ajcvickers, sorry to revive this "old" issue. We are facing some troubling query right now regarding truncated concat'ed strings, and we would like to show the code and query in question. However, since this is company and legal related, I can't just paste the code on here. Is there any channel where I can submit this, without having to post company related code? Edit: I decided to have a look at it myself, and found the issue. I created an issue for it: #27206 |
Originally reported as #23634 (comment) by @saliksaly.
Using CONCAT for strings is not so good due to string truncation to 4000 chars in SQL server :-(
Now the migrations run without error (Microsoft.Data.SqlClient.SqlException (0x80131904): The concat function requires 2 to 254 arguments.) but my seeded strings are now truncated in the database. Silently!
Here are some resources for this SQL server behavior:
https://stackoverflow.com/questions/4547821/using-varcharmax-with-string-concatenation-in-sql-server-2005
https://stackoverflow.com/questions/4833549/nvarcharmax-still-being-truncated
https://sqlundercover.com/2017/09/27/concatenation-truncation-are-your-strings-being-truncated/
Is there any workaround for this? We have had CSHTML templates in seed data and now it would not be posible in new version of .net?
The text was updated successfully, but these errors were encountered: