I've just checked the new futures in Entity Framework Core 2.0. There is a really nice feature in it called "String interpolation in raw SQL methods" which is described here.
It says that this code:
var city = "Redmond";
using (var context = CreateContext())
{
context.Customers.FromSql($@"
SELECT *
FROM Customers
WHERE City = {city}");
}
creates this query:
SELECT *
FROM Customers
WHERE City = @p0
It is really strange to me! How FromSql method is written as it has just and input of type string.
How does it understand it is an interpolated string, and then create a parameter @p0 query for it? How can I write a method like FromSql aware of how its string parameters are created?
FromSQL?FromSql. You mean that it replaces all values with parameters? For example if I hadAND IsActive = 1, it would create another@p2, despite is is not being interpolated?FromSqlaccepts aFormattableString, not astring.