Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ protected SqlServerStringTypeMapping(RelationalTypeMappingParameters parameters,
_maxSize = AnsiMax;
}

_isUtf16 = parameters.Unicode && parameters.StoreType.StartsWith("n", StringComparison.OrdinalIgnoreCase);
_isUtf16 = parameters.Unicode
&& (parameters.StoreType.StartsWith("n", StringComparison.OrdinalIgnoreCase)
|| parameters.StoreType.StartsWith("xml", StringComparison.OrdinalIgnoreCase));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equals("xml", StringComparison.OrdinalIgnoreCase)) ?

_sqlDbType = sqlDbType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ public void GenerateProviderValueSqlLiteral_works_unicode(string value, string e
var mapping = new SqlServerStringTypeMapping("nvarchar(max)", unicode: true);
Assert.Equal(expected, mapping.GenerateProviderValueSqlLiteral(value));
}

[Theory, InlineData("", "N''"), InlineData("it", "N'it'"), InlineData("I'm", "N'I''m'"),
InlineData("<x Attr=\"\U0001F62D\" />", "N'<x Attr=\"\U0001F62D\" />'"),
InlineData("\n", "nchar(10)"),
InlineData("it\n", "CONCAT(CAST(N'it' AS nvarchar(max)), nchar(10))")]
public void GenerateProviderValueSqlLiteral_works_xml(string value, string expected)
{
var mapping = new SqlServerStringTypeMapping("xml", unicode: true, storeTypePostfix: StoreTypePostfix.None);
Assert.Equal(expected, mapping.GenerateProviderValueSqlLiteral(value));
}
}