var sql=“insert into talele(data)value(‘{data:123}’);”;
this.Database.ExecuteSqlCommand(sql);
System.FormatException: Input string was not in a correct format.
at System.Text.StringBuilder.FormatError()
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.Format(String format, Object[] args)
at Microsoft.EntityFrameworkCore.Storage.Internal.RawSqlCommandBuilder.Build(String sql, IReadOnlyList`1 parameters)
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlCommand(DatabaseFacade databaseFacade, String sql, Object[] parameters)
Looks like this line needs to check that substitutions.Count > 0, perhaps?
https://github.com/aspnet/EntityFramework/blob/f386095005e46ea3aa4d677e4439cdac113dbfb1/src/EFCore.Relational/Storage/Internal/RawSqlCommandBuilder.cs#L76
this is bug
@gujunxiong The curly braces are interpreted as place markers for query parameters. If you want to include curly braces without them being interpreted in this way, then you'll need to escape them--something like this:
C#
var sql=“insert into talele(data)value(‘{{data:123}}’);”;
this.Database.ExecuteSqlCommand(sql);
Leaving this issue open since we should wrap the FormatException and provide some guidance on this.
The same problem if I have curly braces in the comment message into my SQL script.
-- some comment message {GUID}
select newId();