문제

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.

https://github.com/codai/Sharp-Lite/blob/master/Example/MyStore/app/MyStore.NHibernateProvider/Conventions.cs

Line 32: I changed it to following code

classCustomizer.Table("[" + Inflector.Net.Inflector.Singularize(type.Name.ToString()) + "]");
도움이 되었습니까?

해결책

I have already answered this on the mailing list, posting answer here for others to find easily (and the points :)

https://github.com/codai/Sharp-Lite/blob/master/Example/MyStore/app/MyStore.NHibernateProvider/NHibernateInitializer.cs#L19

add: db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;

Should do the trick

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top