You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Separate methods for raw SQL that leverage interpolated strings #10996
Currently the behavior is different if you call FromSql or ExecuteSqlCommand with an inline interpolated string (parameterization happens) or if you assign the interpolated string to a variable and then pass it to the method (the string is formatted with the arguments).
In some cases customers expect parameterization but it doesn't happen: #10080
In other cases customers expect parameterization not to happen, but it does happen: #10956
This is very confusing and hard to explain. Interpolated strings in C# were simply not designed in a way that works well with having two overloads of the same method in which one works with interpolated strings and the other one with a regular string.
I think we should separate the methods, but we can only do this in major release because it is a breaking change.
This would also imply removing the RawSqlString type.
changed the title [-]Separate methods for raw SQL methods that leverage interpolated strings[/-][+]Separate methods for raw SQL that leverage interpolated strings[/+]on Feb 16, 2018
@NickCraver thanks. We are going to try to address #10080 in the shorter term with a Roslyn analyzer. I think we can probably leverage your tests as tests cases for the analyzer.
@jeremycook my apologies - you wrote FormattableString and my brain read it as IFormattableString even after a few passes. I completely agree on the concrete type: there's no way I can think of to break that approach. If we allowed the interface anywhere...oh yeah, lots of fun. Sorry about that!
Activity
[-]Separate methods for raw SQL methods that leverage interpolated strings[/-][+]Separate methods for raw SQL that leverage interpolated strings[/+]NickCraver commentedon Feb 16, 2018
Absolutely agree with this move. If it helps, I wrote up some more test cases on how this is confusing (and sometimes dangerous) when it first came up here: https://github.com/NickCraver/EFCoreInjectionSample/blob/master/Program.cs
divega commentedon Feb 17, 2018
@NickCraver thanks. We are going to try to address #10080 in the shorter term with a Roslyn analyzer. I think we can probably leverage your tests as tests cases for the analyzer.
cc @anpete
ajcvickers commentedon May 18, 2018
And remove or modify the analyzer?
divega commentedon May 19, 2018
I believe modify. I haven’t thought through all the details but I believe it can still provide value on the string overload.
35 remaining items
Separate FromSql methods into 2 methods (#15018)
NickCraver commentedon Mar 14, 2019
@jeremycook my apologies - you wrote
FormattableStringand my brain read it asIFormattableStringeven after a few passes. I completely agree on the concrete type: there's no way I can think of to break that approach. If we allowed the interface anywhere...oh yeah, lots of fun. Sorry about that!ajcvickers commentedon Mar 31, 2019
Closing since this is now done and the break is documented.