Nhibernate, how to using sql server keyword as table name?
-
14-04-2021 - |
Pergunta
I am building my application using s#arp lite framework. One of my tables is called User
. But User
is a SQL Server 2008 keyword, so it gives me problems.
I tried to modify the code to support tables using SQL Server keywords, butcouldn't get it to work.
Here's the code.
Line 32: I changed it to following code
classCustomizer.Table("[" + Inflector.Net.Inflector.Singularize(type.Name.ToString()) + "]");
Solução
I have already answered this on the mailing list, posting answer here for others to find easily (and the points :)
add: db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
Should do the trick
Outras dicas
This seems vaguely familiar to me. No promises but you can try to use quotes around User, like select * from "User" or supply the schema owner ase well, like select * from Mydb.User.
Hope this helps. Good luck!
You can also do this manually by utilizing NHibernate's non-DB specific escape character: the backtick `
In SQL Server you may do "[User]" but in Oracle it will be different. If you use "`User`" NHibernate will adapt this to the database you are currently working with.
This can be seen on this question: Fluent NHibernate Column Mapping with Reserved Word