0

I am using Dapper.Rainbow and have come across an issue when inserting into a table named 'User'.

I can get other tables to work perfectly, but when try to insert to the Users table it will fail.

I have used the Sql Query inspector to determine that the generated query does not have any [ ] around the table name. Once I recraft the query with square brackets, it works fine.

When I use Table<User>(this, "[Users]"); it will set the private property likelyTableName to the correct value ([User]).

However as soon as database.Init(dbconn,3); it will change the likelyTableName string back to User.

I have been checking out the Dapper-dot-net Github project and looked through the database.cs source for dapper.rainbow, but am at a loss as parts of it are in IL.

Is there a way to get dapper.rainbow to work with a table named User??

Jastill
  • 656
  • 3
  • 15

1 Answers1

1

It is really a bad idea to use reserved words for table (or field, view etc) names. I think that is likely causing you problems. Better to bite the bullet once and change the name, than fight with it forever.

For reference, here are a list of reserved words (to avoid):

http://msdn.microsoft.com/en-us/library/ms189822.aspx

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
  • I do agree with your point, however having looked through the Rainbow code a bit more, I feel like there may be a bug in their code. Some of the Senior Devs at my work are saying that using square brackets is a good practise. And it looks as if Rainbow will never put square brackets around your table name if the table already exists in your DB. – Jastill May 20 '13 at 01:22