Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 114899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:56:02+00:00 2026-05-11T02:56:02+00:00

My application supports both Oracle and MS SQL databases, with slightly different schemas having

  • 0

My application supports both Oracle and MS SQL databases, with slightly different schemas having been implemented for each. One issue I’ve run into is a class that has an auto-increment primary key under MS SQL, but a manually-inserted primary key under Oracle.

Right now, the two different mappings for the class look like this:

Oracle:

<class lazy='false' name='EntityPropertyName' table='entity_property_name' > <id name='ID' column='id' type='Int32' unsaved-value='-1'>   <generator class='increment' /> </id> <property name='Name' column='name'/> 

MS SQL:

<class lazy='false' name='EntityPropertyName' table='entity_property_name' > <id name='ID' column='id' type='Int32' unsaved-value='-1'>   <generator class='native'>   </generator> </id> <property name='Name' column='name'/> 

This isn’t the worst thing in the world, because I can put them into different mapping files and load the correct one at runtime.

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();              if (newDBType == CompanyName.AppName.Data.Enum.DatabaseType.MsSqlServer)             {                 cfg.Properties['dialect'] = 'NHibernate.Dialect.MsSql2000Dialect';                 cfg.Properties['connection.driver_class'] = 'NHibernate.Driver.SqlClientDriver';                 cfg.AddFile('DataTypes\\MSSQLTypes.hbm.xml');             }             else             {                 cfg.Properties['dialect'] = 'NHibernate.Dialect.Oracle9Dialect';                 cfg.Properties['connection.driver_class'] = 'NHibernate.Driver.OracleClientDriver';                 cfg.AddFile('DataTypes\\OracleTypes.hbm.xml');             }              cfg.Properties['connection.provider'] = 'NHibernate.Connection.DriverConnectionProvider';              cfg.Properties['connection.connection_string'] = connectionString;              cfg.AddAssembly('CompanyName.AppName.Data');              Sessions = cfg.BuildSessionFactory(); 

The thing I dislike about this strategy though is that I now have some ugly XML files in my program’s bin directory, which need to be there or the application won’t work. It would be a lot better if I could embed the different files into the resource like I can with my main mapping file, but choose whether to load each file or not at runtime.

Is there any way to do this, or perhaps a different way to solve the problem?


Edit: Thank you, Cristian! You did understand the question, I was just unaware that resources could be loaded by NHibernate like that. Thinking on it, I suppose it makes sense for the AddAssembly method would have to have some way to enumerate and load the resources that it finds!

My solution ended up being:

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();              if (newDBType == CompanyName.AppName.Data.Enum.DatabaseType.MsSqlServer)             {                 cfg.Properties['dialect'] = 'NHibernate.Dialect.MsSql2000Dialect';                 cfg.Properties['connection.driver_class'] = 'NHibernate.Driver.SqlClientDriver';                 cfg.AddInputStream(Assembly.GetExecutingAssembly().GetManifestResourceStream('CompanyName.AppName.Data.DataTypes.MSSQLTypes.hbm.xml'));             }             else             {                 cfg.Properties['dialect'] = 'NHibernate.Dialect.Oracle9Dialect';                 cfg.Properties['connection.driver_class'] = 'NHibernate.Driver.OracleClientDriver';                 cfg.AddInputStream(Assembly.GetExecutingAssembly().GetManifestResourceStream('CompanyName.AppName.Data.DataTypes.OracleTypes.hbm.xml'));             }              cfg.Properties['connection.provider'] = 'NHibernate.Connection.DriverConnectionProvider';              cfg.Properties['connection.connection_string'] = connectionString;              cfg.AddInputStream(Assembly.GetExecutingAssembly().GetManifestResourceStream('CompanyName.AppName.Data.DataTypes.Types.hbm.xml'));              Sessions = cfg.BuildSessionFactory(); 
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:56:03+00:00Added an answer on May 11, 2026 at 2:56 am

    I might be missing your crucial point. NHibernate is quite flexible in how you can feed it the mapping files. e.g.

    cfg.AddInputStream(assembly.GetManifestResourceStream('MyNamespace.MyEmbeddedresource.hbm.xml')); 

    or a custom built xml string:

    cfg.AddXml(myCustomBuildXmlString); 

    You can also add mappings programmatically directly but that’s a bit trickier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can better understand how the Oracle optimizer is making… May 12, 2026 at 12:44 am
  • Editorial Team
    Editorial Team added an answer First make sure, to add the UISearchBar to the tableHeaderView… May 12, 2026 at 12:44 am
  • Editorial Team
    Editorial Team added an answer You need conditional formatting. This allows formatting (including text colour,… May 12, 2026 at 12:44 am

Related Questions

I need to add the ability for users of my software to select records
I am looking for a DBI (or similar) proxy that supports both SQL restrictions
I have a cms which stores comments against articles. These comments can be both
I am creating a simple application and getting stuck with data storage option. To

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.