Dapper.Rainbow column name is not escaped with '[]' for SQL Server

48 views Asked by At

I want to try using Dapper.Rainbow mainly to have the ability to use Snapshotter and generate effective updates.

public class MyEntity
{
    // ...
    public int AK { get; set; }
    public int OR { get; set; } //issue is here
    // ...
}

My domain has many two-letter named fields, one of them is OR.
When it comes to insert through Dapper.Rainbow Table in Database class, the generated SQL looks like this

INSERT INTO MyEntity (.., AK, OR, ...) 
VALUES (...) --SQL syntax is incorrect here, reserved keyword `OR` is used

Is there a way to force using [] so it would be?

INSERT INTO MyEntity (.., [AK], [OR], ...) 
VALUES (...) --SQL syntax is fine

EF Core and Dapper.SimpleCRUD work fine for column OR, but I am looking something more lightweight than EF, but still with some sort of change tracking, so alternatives are also welcome.

1

There are 1 answers

0
J.Memisevic On BEST ANSWER

As from right now this is not possible in Dapper.Rainbow , for creating the query it uses PropertyInfo.Name and when they are building the query they use just :

var sql = "set nocount on insert " + TableName + " (" + cols + ") values (" + colsParams + ") select cast(scope_identity() as int)";

You can check their Gitub.

It is not bad idea though, you could create a PR for improvements yourself or maybe fork the repo and create your own version of the package.