-
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
Migrations containing strings with many line-breaks will truncate strings silently #27206
Comments
I've faced the same issue while importing html templates via seed, it was truncating the template after a lot of investigation came to know its because of the CAST(0 AS bit), NULL, NULL, CONCAT(CAST(N'<!DOCTYPE html PUBLIC.......... |
@dnxit Can you share a small repro project so we can make sure that you are hitting the same issue? |
@AndriySvyryd yeah sure, I've created a sample. just set the connection string and run the sample, by the way I've added generated query from SQL profiler as well. |
SQL script: PS C:\local\code\repros\StringTruncationSampleEF6-main\StringTruncationSampleEF6-main\WebApplication1> dotnet ef migrations script
Build started...
Build succeeded.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 6.0.1 initialized 'DataContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.1' with options: None
IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
BEGIN
CREATE TABLE [__EFMigrationsHistory] (
[MigrationId] nvarchar(150) NOT NULL,
[ProductVersion] nvarchar(32) NOT NULL,
CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
);
END;
GO
BEGIN TRANSACTION;
GO
CREATE TABLE [EmailTemplate] (
[Id] int NOT NULL IDENTITY,
[TemplateName] nvarchar(100) NOT NULL,
[TemplateData] nvarchar(max) NOT NULL,
CONSTRAINT [PK_EmailTemplate] PRIMARY KEY ([Id])
);
GO
IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'TemplateData', N'TemplateName') AND [object_id] = OBJECT_ID(N'[EmailTemplate]'))
SET IDENTITY_INSERT [EmailTemplate] ON;
INSERT INTO [EmailTemplate] ([Id], [TemplateData], [TemplateName])
VALUES (1, CONCAT(CAST(N'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' AS nvarchar(max)), nchar(10), N'<html xmlns="http://www.w3.org/1999/xhtml" style="font-family: ''Helvetica Neue'', Helvetica, Arial, sans-serif; box-sizing: border-
box; font-size: 14px; margin: 0;">', nchar(10), N'<head>', nchar(10), N' <meta name="viewport" content="width=device-width">', nchar(10), N' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">', nchar(10), N' <title>Student Learning Hub</title>', nchar(10), N' <style>', nchar(
10), N' @media only screen and (max-width: 620px) {', nchar(10), N' table[class=body] h1 {', nchar(10), N' font-size: 28px !important;', nchar(10), N' margin-bottom: 10px !important;', nchar(10), N' }', nchar(10), N
' table[class=body] p,', nchar(10), N' table[class=body] ul,', nchar(10), N' table[class=body] ol,', nchar(10), N' table[class=body] td,', nchar(10), N' table[class=body] span,', nchar(10), N' table[cl
ass=body] a {', nchar(10), N' font-size: 16px !important;', nchar(10), N' }', nchar(10), N' table[class=body] .wrapper,', nchar(10), N' table[class=body] .article {', nchar(10), N' padding: 10px !i
mportant;', nchar(10), N' }', nchar(10), N' table[class=body] .content {', nchar(10), N' padding: 0 !important;', nchar(10), N' }', nchar(10), N' table[class=body] .container {', nchar(10), N'
padding: 0 !important;', nchar(10), N' width: 100% !important;', nchar(10), N' }', nchar(10), N' table[class=body] .main {', nchar(10), N' border-left-width: 0 !important;', nchar(10), N'
border-radius: 0 !important;', nchar(10), N' border-right-width: 0 !important;', nchar(10), N' }', nchar(10), N' table[class=body] .btn table {', nchar(10), N' width: 100% !important;'
, nchar(10), N' }', nchar(10), N' table[class=body] .btn a {', nchar(10), N' width: 100% !important;', nchar(10), N' }', nchar(10), N' table[class=body] .img-responsive {', nchar(10), N'
height: auto !important;', nchar(10), N' max-width: 100% !important;', nchar(10), N' width: auto !important;', nchar(10), N' }', nchar(10), N' }', nchar(10), N' @media all {', nchar(10), N'
.ExternalClass {', nchar(10), N' width: 100%;', nchar(10), N' }', nchar(10), N' .ExternalClass,', nchar(10), N' .ExternalClass p,', nchar(10), N' .Externa
lClass span,', nchar(10), N' .ExternalClass font,', nchar(10), N' .ExternalClass td,', nchar(10), N' .ExternalClass div {', nchar(10), N' line-height: 100%;', nchar(10), N'
}', nchar(10), N' .apple-link a {', nchar(10), N' color: inherit !important;', nchar(10), N' font-family: inherit !important;', nchar(10), N' font-size: inherit !important;', nchar(10), N'
font-weight: inherit !important;', nchar(10), N' line-height: inherit !important;', nchar(10), N' text-decoration: none !important;', nchar(10), N' }', nchar(10), N' #Message
ViewBody a {', nchar(10), N' color: inherit;', nchar(10), N' text-decoration: none;', nchar(10), N' font-size: inherit;', nchar(10), N' font-family: inherit;', nchar(10), N' font-wei
ght: inherit;', nchar(10), N' line-height: inherit;', nchar(10), N' }', nchar(10), N' .btn-primary table td:hover {', nchar(10), N' background-color: #34495e !important;', nchar(10), N' }', nchar(10), N
' .btn-primary a:hover {', nchar(10), N' background-color: #34495e !important;', nchar(10), N' border-color: #34495e !important;', nchar(10), N' }', nchar(10), N' }', nchar(10), N' </style>', nchar
(10), N'</head>', nchar(10), N'<body class="" style="background-color: #f6f6f6; font-family: sans-serif; -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.4; margin: 0; padding: 0; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">', nchar(10), N' <table border="0" cellpadding="0
" cellspacing="0" class="body" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; background-color: #f6f6f6;">', nchar(10), N' <tr>', nchar(10), N' <td style="font-family: sans-serif; font-size: 14px; vertical-align: top;"> </td>',
nchar(10), N' <td class="container" style="font-family: sans-serif; font-size: 14px; vertical-align: top; display: block; Margin: 0 auto; max-width: 580px; padding: 10px; width: 580px;">', nchar(10), N' <div class="content" style="box-sizing: border-box; display: blo
ck; Margin: 0 auto; max-width: 580px; padding: 10px;">', nchar(10), N' <span class="preheader" style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">This is preheader text. So
me clients will show this text as a preview.</span>', nchar(10), N' <table class="main" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; background: #ffffff; border-radius: 3px;">', nchar(10), N'
<tr style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0; font-weight:500;">', nchar(10), N' <td class="alert alert-warning" style="font-family: ''Helvetica Neue'',Helvetica,Arial,s
ans-serif; box-sizing: border-box; font-size: 16px; vertical-align: top; color:#00468C; font-weight:600; text-align: center; border-radius: 3px 3px 0 0; background-color:#fff ; margin: 0; padding: 20px;" align="center" bgcolor="#FF9F00" valign="top">', nchar(10), N'
Email Confirmation', nchar(10), N' </td>', nchar(10), N' </tr>', nchar(10), N' <tr>', nchar(10), N'
<td class="wrapper" style="font-family: sans-serif; font-size: 14px; vertical-align: top; box-sizing: border-box; padding: 20px;">', nchar(10), N' <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-ls
pace: 0pt; mso-table-rspace: 0pt; width: 100%;">', nchar(10), N' <tr>', nchar(10), N' <td class="alert alert-warning">', nchar(10), N'
<hr noshade size="2" style="background-color: #00468C" />', nchar(10), N' <br />', nchar(10), N'
<p class="content-block" style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">', nchar(10), N'
Please confirm your email address by clicking the link below.', nchar(10), N' </p>', nchar(10), N' <table border="0" cellpadding="0
" cellspacing="0" class="btn btn-primary" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; box-sizing: border-box;">', nchar(10), N' <tbody>', nchar(10), N'
<tr style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">', nchar(10), N'
<td class="content-block" style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">', nchar(10), N'
We may need to send you critical information about our service and it is important that we have an accurate email address.', nchar(10), N' </td>',
nchar(10), N' </tr>', nchar(10), N' <tr style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizin
g: border-box; font-size: 14px; margin: 0;">', nchar(10), N' <td class="content-block" itemprop="handler" itemscope=itemscope itemtype="http://schema.org/HttpActionHandler" style="font-family: ''Helvetica
Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">', nchar(10), N' <a href="[[Link]]" class="btn-primary" i
temprop="url" style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; color: #FFF; text-decoration: none; line-height: 2em; font-weight: bold; text-align: center; cursor: pointer; display: inline-block; border-radius: 5px; text-transform: capitalize; backgroun
d-color: #348eda; margin: 0; border-color: #348eda; border-style: solid; border-width: 10px 20px;">Confirm email address</a>', nchar(10), N' </td>', nchar(10), N'
</tr>', nchar(10), N' <tr style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">', nchar(10)
, N' <td class="content-block" style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">'
, nchar(10), N' Or you can call admin office and share this OTP for confirmation.', nchar(10), N'
<p class="content-block" style="color: dodgerblue; font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 16px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">', nchar(10), N'
<b>[[OTP]]</b>', nchar(10), N' </p>', CONCAT(nchar(10), N'
</td>', nchar(10), N' </tr>', nchar(10), N' </tbody>', nchar(10), N'
</table>', nchar(10), N' <br />', nchar(10), N' </td>', nchar(10
), N' </tr>', nchar(10), N' <tr style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">', nchar(10), N'
<td class="content-block" style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">', nchar(10), N'
Email our support team at <a href="mailto:[[SupportEmail]]">[[SupportEmail]]</a>, or call us on <a href="tel:[[SupportPhone]]">[[SupportPhone]]</a> for any queries.', nchar(10), N'
</td>', nchar(10), N' </tr>', nchar(10), N' <tr style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">', n
char(10), N' <td class="content-block" style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">', nchar(10), N'
<b>Best Wishes</b> <br />', nchar(10), N' <b>Testing System </b>', nchar(10), N'
</td>', nchar(10), N' </tr>', nchar(10), N' </table>', nchar(10), N' </td>', nchar(10), N'
</tr>', nchar(10), N' <tr>', nchar(10), N' <td class="aligncenter content-block" style="font-family: ''Helvetica Neue'',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px;', nchar(10), N'
vertical-align: top; color: #fff; text-align: left; margin: 0; padding: 20px; border-bottom: solid 4px #0b0b0b; background:#00468C" bgcolo="#00468C" align="center" valign="top">', nchar(10), N'
The Test System is your one-stop-shop for all undergraduate learning supports and resources. Visit us early and often to build the skills, strategies, and behaviours that are essential to become a confident and independent learner.<br /><br />', nchar(10), N'
c [[Year]] Test System. All rights reserved.', nchar(10), N' </td>', nchar(10), N' </tr>', nchar(10), N' </table>', nchar(10), N'
<div class="footer" style="clear: both; Margin-top: 10px; text-align: center; width: 100%;">', nchar(10), N' <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width:
100%;">', nchar(10), N' <tr>', nchar(10), N' <td class="content-block" style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; font-size: 12px; color: #999999;
text-align: center;">', nchar(10), N' <span class="apple-link" style="color: #999999; font-size: 12px; text-align: center;">The Testing System</span>', nchar(10), N' </td>', nchar(10), N'
</tr>', nchar(10), N' </table>', nchar(10), N' </div>', nchar(10), N' </div>', nchar(10), N' </td>', nchar(10), N'
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top;"> </td>', nchar(10), N' </tr>', nchar(10), N' </table>', nchar(10), N'</body>', nchar(10), N'</html>')), N'Email Confirmation');
IF EXISTS (SELECT * FROM [sys].[identity_columns] WHERE [name] IN (N'Id', N'TemplateData', N'TemplateName') AND [object_id] = OBJECT_ID(N'[EmailTemplate]'))
SET IDENTITY_INSERT [EmailTemplate] OFF;
GO
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20220218195810_One', N'6.0.1');
GO
COMMIT;
GO
|
Simplified repro: Not for triage: confirmed that only the first CONCAT has a CAST. This means that only around 85 lines of text can be included (since CR/LF are expanded) until the issue reocurs. C#
INSERT INTO [Blogs] ([Id], [Title])
VALUES (1, CONCAT(CAST(N'000' AS nvarchar(max)), nchar(13), nchar(10), N'001', nchar(13), nchar(10), N'002', nchar(13), nchar(10), N'003', nchar(13), nchar(10), N'004', nchar(13), nchar(10), N'005', nchar(13), nchar(10), N'006', nchar(13), nchar(10), N'007', nchar(13), nchar(10), N'008', nchar(13), nchar(10), N
'009', nchar(13), nchar(10), N'010', nchar(13), nchar(10), N'011', nchar(13), nchar(10), N'012', nchar(13), nchar(10), N'013', nchar(13), nchar(10), N'014', nchar(13), nchar(10), N'015', nchar(13), nchar(10), N'016', nchar(13), nchar(10), N'017', nchar(13), nchar(10), N'018', nchar(13), nchar(10), N'019', nchar
(13), nchar(10), N'020', nchar(13), nchar(10), N'021', nchar(13), nchar(10), N'022', nchar(13), nchar(10), N'023', nchar(13), nchar(10), N'024', nchar(13), nchar(10), N'025', nchar(13), nchar(10), N'026', nchar(13), nchar(10), N'027', nchar(13), nchar(10), N'028', nchar(13), nchar(10), N'029', nchar(13), nchar(
10), N'030', nchar(13), nchar(10), N'031', nchar(13), nchar(10), N'032', nchar(13), nchar(10), N'033', nchar(13), nchar(10), N'034', nchar(13), nchar(10), N'035', nchar(13), nchar(10), N'036', nchar(13), nchar(10), N'037', nchar(13), nchar(10), N'038', nchar(13), nchar(10), N'039', nchar(13), nchar(10), N'040',
nchar(13), nchar(10), N'041', nchar(13), nchar(10), N'042', nchar(13), nchar(10), N'043', nchar(13), nchar(10), N'044', nchar(13), nchar(10), N'045', nchar(13), nchar(10), N'046', nchar(13), nchar(10), N'047', nchar(13), nchar(10), N'048', nchar(13), nchar(10), N'049', nchar(13), nchar(10), N'050', nchar(13),
nchar(10), N'051', nchar(13), nchar(10), N'052', nchar(13), nchar(10), N'053', nchar(13), nchar(10), N'054', nchar(13), nchar(10), N'055', nchar(13), nchar(10), N'056', nchar(13), nchar(10), N'057', nchar(13), nchar(10), N'058', nchar(13), nchar(10), N'059', nchar(13), nchar(10), N'060', nchar(13), nchar(10), N
'061', nchar(13), nchar(10), N'062', nchar(13), nchar(10), N'063', nchar(13), nchar(10), N'064', nchar(13), nchar(10), N'065', nchar(13), nchar(10), N'066', nchar(13), nchar(10), N'067', nchar(13), nchar(10), N'068', nchar(13), nchar(10), N'069', nchar(13), nchar(10), N'070', nchar(13), nchar(10), N'071', nchar
(13), nchar(10), N'072', nchar(13), nchar(10), N'073', nchar(13), nchar(10), N'074', nchar(13), nchar(10), N'075', nchar(13), nchar(10), N'076', nchar(13), nchar(10), N'077', nchar(13), nchar(10), N'078', nchar(13), nchar(10), N'079', nchar(13), nchar(10), N'080', nchar(13), nchar(10), N'081', nchar(13), nchar(
10), N'082', nchar(13), nchar(10), N'083', nchar(13), nchar(10), N'084', CONCAT(nchar(13), nchar(10), N'085', nchar(13), nchar(10), N'086', nchar(13), nchar(10), N'087', nchar(13), nchar(10), N'088', nchar(13), nchar(10), N'089', nchar(13), nchar(10), N'090', nchar(13), nchar(10), N'091', nchar(13), nchar(10),
N'092', nchar(13), nchar(10), N'093', nchar(13), nchar(10), N'094', nchar(13), nchar(10), N'095', nchar(13), nchar(10), N'096', nchar(13), nchar(10), N'097', nchar(13), nchar(10), N'098', nchar(13), nchar(10), N'099', nchar(13), nchar(10), N'100', nchar(13), nchar(10), N'101', nchar(13), nchar(10), N'102', ncha
r(13), nchar(10), N'103', nchar(13), nchar(10), N'104', nchar(13), nchar(10), N'105', nchar(13), nchar(10), N'106', nchar(13), nchar(10), N'107', nchar(13), nchar(10), N'108', nchar(13), nchar(10), N'109', nchar(13), nchar(10), N'110', nchar(13), nchar(10), N'111', nchar(13), nchar(10), N'112', nchar(13), nchar
(10), N'113', nchar(13), nchar(10), N'114', nchar(13), nchar(10), N'115', nchar(13), nchar(10), N'116', nchar(13), nchar(10), N'117', nchar(13), nchar(10), N'118', nchar(13), nchar(10), N'119', nchar(13), nchar(10), N'120', nchar(13), nchar(10), N'121', nchar(13), nchar(10), N'122', nchar(13), nchar(10), N'123'
, nchar(13), nchar(10), N'124', nchar(13), nchar(10), N'125', nchar(13), nchar(10), N'126', nchar(13), nchar(10), N'127', nchar(13), nchar(10), N'128', nchar(13), nchar(10), N'129', nchar(13), nchar(10), N'130', nchar(13), nchar(10), N'131', nchar(13), nchar(10), N'132', nchar(13), nchar(10), N'133', nchar(13),
nchar(10), N'134', nchar(13), nchar(10), N'135', nchar(13), nchar(10), N'136', nchar(13), nchar(10), N'137', nchar(13), nchar(10), N'138', nchar(13), nchar(10), N'139', nchar(13), nchar(10), N'140', nchar(13), nchar(10), N'141', nchar(13), nchar(10), N'142', nchar(13), nchar(10), N'143', nchar(13), nchar(10),
N'144', nchar(13), nchar(10), N'145', nchar(13), nchar(10), N'146', nchar(13), nchar(10), N'147', nchar(13), nchar(10), N'148', nchar(13), nchar(10), N'149', nchar(13), nchar(10), N'150', nchar(13), nchar(10), N'151', nchar(13), nchar(10), N'152', nchar(13), nchar(10), N'153', nchar(13), nchar(10), N'154', ncha
r(13), nchar(10), N'155', nchar(13), nchar(10), N'156', nchar(13), nchar(10), N'157', nchar(13), nchar(10), N'158', nchar(13), nchar(10), N'159', nchar(13), nchar(10), N'160', nchar(13), nchar(10), N'161', nchar(13), nchar(10), N'162', nchar(13), nchar(10), N'163', nchar(13), nchar(10), N'164', nchar(13), nchar
(10), N'165', nchar(13), nchar(10), N'166', nchar(13), nchar(10), N'167', nchar(13), nchar(10), N'168', nchar(13), CONCAT(nchar(10), N'169', nchar(13), nchar(10), N'170', nchar(13), nchar(10), N'171', nchar(13), nchar(10), N'172', nchar(13), nchar(10), N'173', nchar(13), nchar(10), N'174', nchar(13), nchar(10),
N'175', nchar(13), nchar(10), N'176', nchar(13), nchar(10), N'177', nchar(13), nchar(10), N'178', nchar(13), nchar(10), N'179', nchar(13), nchar(10), N'180', nchar(13), nchar(10), N'181', nchar(13), nchar(10), N'182', nchar(13), nchar(10), N'183', nchar(13), nchar(10), N'184', nchar(13), nchar(10), N'185', nch
ar(13), nchar(10), N'186', nchar(13), nchar(10), N'187', nchar(13), nchar(10), N'188', nchar(13), nchar(10), N'189', nchar(13), nchar(10), N'190', nchar(13), nchar(10), N'191', nchar(13), nchar(10), N'192', nchar(13), nchar(10), N'193', nchar(13), nchar(10), N'194', nchar(13), nchar(10), N'195', nchar(13), ncha
r(10), N'196', nchar(13), nchar(10), N'197', nchar(13), nchar(10), N'198', nchar(13), nchar(10), N'199', nchar(13), nchar(10), N'200', nchar(13), nchar(10), N'201', nchar(13), nchar(10), N'202', nchar(13), nchar(10), N'203', nchar(13), nchar(10), N'204', nchar(13), nchar(10), N'205', nchar(13), nchar(10), N'206
', nchar(13), nchar(10), N'207', nchar(13), nchar(10), N'208', nchar(13), nchar(10), N'209', nchar(13), nchar(10), N'210', nchar(13), nchar(10), N'211', nchar(13), nchar(10), N'212', nchar(13), nchar(10), N'213', nchar(13), nchar(10), N'214', nchar(13), nchar(10), N'215', nchar(13), nchar(10), N'216', nchar(13)
, nchar(10), N'217', nchar(13), nchar(10), N'218', nchar(13), nchar(10), N'219', nchar(13), nchar(10), N'220', nchar(13), nchar(10), N'221', nchar(13), nchar(10), N'222', nchar(13), nchar(10), N'223', nchar(13), nchar(10), N'224', nchar(13), nchar(10), N'225', nchar(13), nchar(10), N'226', nchar(13), nchar(10),
N'227', nchar(13), nchar(10), N'228', nchar(13), nchar(10), N'229', nchar(13), nchar(10), N'230', nchar(13), nchar(10), N'231', nchar(13), nchar(10), N'232', nchar(13), nchar(10), N'233', nchar(13), nchar(10), N'234', nchar(13), nchar(10), N'235', nchar(13), nchar(10), N'236', nchar(13), nchar(10), N'237', nch
ar(13), nchar(10), N'238', nchar(13), nchar(10), N'239', nchar(13), nchar(10), N'240', nchar(13), nchar(10), N'241', nchar(13), nchar(10), N'242', nchar(13), nchar(10), N'243', nchar(13), nchar(10), N'244', nchar(13), nchar(10), N'245', nchar(13), nchar(10), N'246', nchar(13), nchar(10), N'247', nchar(13), ncha
r(10), N'248', nchar(13), nchar(10), N'249', nchar(13), nchar(10), N'250', nchar(13), nchar(10), N'251', nchar(13), nchar(10), N'252', nchar(13), nchar(10), CONCAT(N'253', nchar(13), nchar(10), N'254', nchar(13), nchar(10), N'255', nchar(13), nchar(10), N'256', nchar(13), nchar(10), N'257', nchar(13), nchar(10)
, N'258', nchar(13), nchar(10), N'259', nchar(13), nchar(10), N'260', nchar(13), nchar(10), N'261', nchar(13), nchar(10), N'262', nchar(13), nchar(10), N'263', nchar(13), nchar(10), N'264', nchar(13), nchar(10), N'265', nchar(13), nchar(10), N'266', nchar(13), nchar(10), N'267', nchar(13), nchar(10), N'268', nc
har(13), nchar(10), N'269', nchar(13), nchar(10), N'270', nchar(13), nchar(10), N'271', nchar(13), nchar(10), N'272', nchar(13), nchar(10), N'273', nchar(13), nchar(10), N'274', nchar(13), nchar(10), N'275', nchar(13), nchar(10), N'276', nchar(13), nchar(10), N'277', nchar(13), nchar(10), N'278', nchar(13), nch
ar(10), N'279', nchar(13), nchar(10), N'280', nchar(13), nchar(10), N'281', nchar(13), nchar(10), N'282', nchar(13), nchar(10), N'283', nchar(13), nchar(10), N'284', nchar(13), nchar(10), N'285', nchar(13), nchar(10), N'286', nchar(13), nchar(10), N'287', nchar(13), nchar(10), N'288', nchar(13), nchar(10), N'28
9', nchar(13), nchar(10), N'290', nchar(13), nchar(10), N'291', nchar(13), nchar(10), N'292', nchar(13), nchar(10), N'293', nchar(13), nchar(10), N'294', nchar(13), nchar(10), N'295', nchar(13), nchar(10), N'296', nchar(13), nchar(10), N'297', nchar(13), nchar(10), N'298', nchar(13), nchar(10), N'299', nchar(13
), nchar(10)))))); |
Hey, can we also add this fix for 6.0.x ? Seems like it also reproduces there. |
/cc @smitpatel |
Description
This was originally filed in #24112 and got fixed in #24944.
We first found out about this issue when inserting a large legal text into our database, which contains a lot of line breaks. EF Core generates a large script which uses
CONCAT()
with up to 254 arguments, before starting a newCONCAT()
. (\r and \n get converted to nchar(10) and nchar(13) and will be concatenated with the rest of the text)As in #24112 described, there is an issue with
CONCAT
if you don't CAST the first parameter asnvarchar(max)
the sql server will assume the 4000 byte limit.This was fixed with #24944 by adding a
CAST
to the first parameter ofCONCAT
. However, subsequentCONCAT
s will not use aCAST
. This will lead to silently truncated strings in the database.I already had a look at the code and decided to fix it and contribute to this project.
efcore/src/EFCore.SqlServer/Storage/Internal/SqlServerStringTypeMapping.cs
Lines 312 to 317 in 6523335
It seems that resetting the
castApplied
flag to false inside the if fixes the issue.As per the the contribution guidelines, I am requesting permission to file a PR.
Include provider and version information
EF Core version: latest (main branch)
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 10
IDE: (e.g. Visual Studio 2019 16.3)
The text was updated successfully, but these errors were encountered: