0

I'm using NHibernate to access both an Oracle and a SQL Server CE database. I'm syncing the Oracle db to SQL Server CE to be able to use the program offline.

I'm forced to use the user concept in Oracle an does so by the "."-notation in the map file. So for example to get the USER table, my map file looks like this:

<class name="DatabaseLayer.Classes.Users" lazy="false" table="ADM.USER">

In the SQL Server CE db I have simply created a table with the name ADM.USER and using MSF I managed to sync the data to my offline db. However when trying to load from the table with NHibernate I get an error message saying that there are no USER table... It's like it just has forgotten the ADM.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Markus
  • 3,297
  • 4
  • 31
  • 52
  • try to add `auto-quote` – A.B.Cade Mar 15 '12 at 15:29
  • @A.B.Cade: nae, I get a `The element 'property' in namespace 'urn:nhibernate-mapping-2.2' cannot contain text. List of possible elements expected: 'meta, column, formula, type' in namespace 'urn:nhibernate-mapping-2.2'.` exception – Markus Mar 15 '12 at 15:43
  • maybe this can help http://stackoverflow.com/questions/1398893/how-to-auto-quote-keywords-in-nhibernate-with-ms-sql – A.B.Cade Mar 15 '12 at 15:47
  • @A.B.Cade: From what I can gather from the text that might work. However I can't get it working so I think I'll go with VahidN's way. – Markus Mar 16 '12 at 09:12

1 Answers1

1

Change your mapping to:

<class name="DatabaseLayer.Classes.Users" lazy="false" table="[ADM.USER]">

Now it should work (tested).

VahidN
  • 18,457
  • 8
  • 73
  • 117
  • Oh noo... That did work in SQL CE, however, it didn't work in Oracle any longer :( – Markus Mar 20 '12 at 07:40
  • You need to use double quotes in Oracle, more info: http://stackoverflow.com/questions/1162381/how-do-i-escape-a-reserved-word-in-oracle – VahidN Mar 20 '12 at 09:13
  • But... Maybe I missed out on something here, but isn't the purpose with (N)Hibernate that the same code should be usable whatever database it is connected to? At least in my design the connection to the different db's is made with the same code. – Markus Mar 20 '12 at 14:24
  • "ADM.USER" is not a keyword, so NHibernate will not "auto-quote" it as "A.B.Cade" mentioned. NH will "auto-quote" "USER" automatically for you based on the selected db, because it's a keyword. – VahidN Mar 20 '12 at 18:42
  • Also you can force NH to auto-quote everything by implementing INamingStrategy interface, more info: http://stackoverflow.com/questions/515985/how-to-use-nhibernate-with-variable-or-dynamic-table-names-like-jan08tran-feb08t – VahidN Mar 20 '12 at 19:02
  • But would I then have to make different strategies for the different databases? – Markus Mar 21 '12 at 07:18
  • Yes, Or try adding `backtick` (table="`ADM.USER`"). NH will translated it to an appropriate dialect specific quote character at runtime. – VahidN Mar 21 '12 at 08:10