DapperLib / Dapper.Contrib

Dapper community contributions - additional extensions for Dapper
Other
267 stars 99 forks source link

GetAsync fails on SQL Server when the primary key property is a reserved SQL keyword #150

Open ghills opened 1 year ago

ghills commented 1 year ago

https://github.com/DapperLib/Dapper.Contrib/blob/cf24f6bdc577b1e071c3764ddfb2cf3382531405/src/Dapper.Contrib/SqlMapperExtensions.Async.cs#L33

The query building for Get/GetAsync do simple string formatting to include the property name for the primary key of the table instead of formatting the escaped column name.

For example, a property named Key with the ExplicitKeyAttribute should work but fails because KEY is a reserved SQL keyword. The column name should be included as WHERE [Key] = @id instead.