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
This is a pretty subtle detail if you are not paying attention and do not already understand how FormattableStrings become strings unless you are explicit about maintaining the FormattableString type. It seems like providing an example of correct usage or elaborating on incorrect usage would help, as could linking to related documentation.
For example:
// UNSAFE: In this case sql is implicitly cast to a plain old string and which results in FormSql not being able to parameterize minAge.
var sql = $"SELECT * FROM People WHERE Age > {minAge}";
var query = context.People.FromSql(sql);
// SAFE: By explicitly declaring that sql as a FormattableString, FromSql will be able to parameterize minAge.
FormattableString sql = $"SELECT * FROM People WHERE Age > {minAge}";
var query = context.People.FromSql(sql);
Even more subtle is a formattable string that is composed of formattable strings may not result in parameterization like one might assume. Frankly it would be nice to enable throwing instead of only logging on potentially unsafe queries, but that's an issue for another day.
Activity
ajcvickers commentedon Nov 9, 2018
@jeremycook Your points are very valid. We plan to make changes to the API in 3.0. See dotnet/efcore#10996
ajcvickers commentedon Aug 29, 2019
Note for triage: should we update the 2.x docs here?