EthernetIP
EthernetIP

Reputation: 13

Dapper parameters not working?

Dapper 1.34 (on earlier Dapper ver like 1.1x this worked fine).

db.Query(@"Select [whatever] from @TableName Where [PREFIX]='@Prefix' order by [something] desc", new { TableName = tableName, Prefix = prefix })

Error: System.Data.SqlClient.SqlException (0x80131904): Must declare the table variable "@TableName".

I get same error trying to define DynamicParameters and passing those.

======= I am currently doing string substitution {%1} .. but that does not seem acceptable ...

Can I please get a sample, also looking at test class for dapper I cant see it running, maybe something wrong with my project setup ?

Upvotes: 1

Views: 1437

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064204

No, that has never worked fine, due to how SQL works:

  • table names cannot be parameterized, and dapper has never offered this; that could work if you pass in a DataTable as a table-valued-parameter, though - which dapper does support - but I don't think this is what you are after
  • '@Prefix' is a string literal; you just mean @Prefix (no single quotes)

Upvotes: 0

Related Questions