views:

17

answers:

1

Hi, I am working on an asp.net business application and using nhibernate. My objective of using nhibernate is to minimize/avoid application porting effort on different databases(Oracle, SQL Server, Postgres etc).

I have a scenario where i have to dynamically check the database table schema and build some functionality on it. First thing comes to my mind is that to create stored procedures and port it on different databases. My stored procedure looks like this...


SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = (
    SELECT MasterTableName FROM SystemDocument WHERE DocId = @vDocumentID
)

Now i have 2 questions here...

1- Is there any alternate in NHibernate to achieve this by avoiding stored procedures?

2- If answer of the first question is NO :( then how can i fill a dto/POCO that can contain the columns and their types of the table without mapping it with nhibernate?

I shall be very thankful for your suggestions on this.

Thanks, Asif

A: 

You can use regular sql and project that onto a dto object. I'd use a named query so it will be easier to change. I don't know if there is a way to auto map these named query based on the current dialect in use.

dotjoe
Thanks for the answer, but if i use a named query, it will not be portable for the databases other than sql server. Is there any workaround??
asif
Yeah that's the problem. I've never really dealt with this before, but I guess you'd need multiple versions of this query for each dialect. So multiple hbm.xml files with the same named-query just diffent implementations. Then you'd have to remember to use the right one depending on dialect.
dotjoe