loading...

re: Safer C# with the nameof operator VIEW POST

FULL DISCUSSION
 

I love this, it becomes really useful for Dapper(or any other raw SQL) statements to guarantee properly mapped objects.

var sql = $@"
    SELECT
        CustomerId AS {nameof(Customer.Id)}
      , CustomerName AS {nameof(Customer.Name)}
      , CustomerBalance AS {nameof(Customer.Balance)}
    FROM dbo.Customers
    WHERE CustomerId = @CustomerId;";
 

Oh that's fantastic. I hadn't even thought of that use case. Love it!

Code of Conduct Report abuse