Dapper.Contrib: Incorrect syntax near the keyword 'Table'

Created on 16 Aug 2017  路  6Comments  路  Source: StackExchange/Dapper

Hi!

When genious devs of closedsource application uses keywords for column names dapper doesn't work well, afaik this can be resolved by putting "" (double quotes) around column names.

Sadly i can't change database structure, so i'll have to live with manual queries for now :)

EDIT: '' around the tablenames work on SQL Server 2016 at least (This is where i've tested)

Most helpful comment

@Lillecarl i found a workaround here;
I was using tablename => "User"

I tried Table attribute with square bracket.

[Table("[User]")] public class User { }

I think you also use it for column names like => [Column("[Table]")]

All 6 comments

Not only column names, table names as well. Square brackets can be used for table names.

This Line

should be

var cmd = $"insert into [{name}] ({sbColumnList}) values ({sbParameterList})";

@Zopitirik That won't wolve the issue with column names though, but it's a start.

@Lillecarl they fixed column name problem on #336 this line
function name is "AppendColumnName", i just saw that.

Now we need AppendColumnName like AppendTableName at "interface ISqlAdapter"

@Lillecarl i found a workaround here;
I was using tablename => "User"

I tried Table attribute with square bracket.

[Table("[User]")] public class User { }

I think you also use it for column names like => [Column("[Table]")]

@Zopitirik Aye smart! That'll do for now! :)

Closing this as there's a workaround for this specific issue, but we'll address this more holistically in #722.

Was this page helpful?
0 / 5 - 0 ratings