efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

Switch to C# 11 raw string literals for SQL baselines

Open roji opened this issue 3 years ago • 0 comments

@dotnet/efteam, I needed a break from real work so I changed al SQL baselines to use the new raw string literals... Take a look, I think it looks great!

        AssertSql(
"""
DELETE FROM "Animals" AS a
WHERE a."Discriminator" = 'Kiwi' AND a."CountryId" = 1 AND a."Name" = 'Great spotted kiwi'
""");

Note that for PostgreSQL and Sqlite it's even more useful, since double-quotes no longer need to be escaped!

Let's see what people think, I can do the same for EF (https://github.com/dotnet/efcore/issues/28260) (in MQ...)

Part of #2470

Regular expressions

This doesn't work for multi-command executions, need to improve.

Pattern:

(?s)AssertSql\(\n\s*@"(.*?)"\);\n

Replace:

AssertSql\("""
$1
"""\);\n

roji avatar Aug 10 '22 13:08 roji