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

  • SEARCH
  • Home
  • 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 4592628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:34:01+00:00 2026-05-21T22:34:01+00:00

How might I use a stored procedure from NHibernate but at the same time

  • 0

How might I use a stored procedure from NHibernate but at the same time keep the solution database-agnostic and the codebase clean of switch statements with a case for each Dialect?

I expect to create a Named Query per database implementation containing the content of the database-specific sql implementation of the procedure. My dilemma is how best to conditionally invoke the correct named query. Specifically we’re testing against both MySQL and MS SQL Server 2008 dialects at the moment.

Does anyone know how to create a conditional named query map by dialect? (This would allow the various stored procedure implementations to be stored in a single place for easy maintenance.)

Doing something like this is what I’m about to do but I’d rather avoid both the overhead of the runtime check and writing any code that must examine the current database flavor to run properly…

if (nhSession.GetSessionImplementation().Factory.Dialect == NHibernate.Dialect.MySQL5Dialect) {
  // grab the MySQL named query here                
} else {
  // grab the SQL Server named query here
}

Is there a way to do something like this instead? (the below is wishful pseudo-coding…)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<dialect-filter dialect="mysql">
  <sql-query name="spForMySQL" callable="true">
    <query-param name="mySqlP1" type="int" />
    <return alias="OutType" class="Domain.ResultType, Domain">
      <return class="ResultType">
        <return-property column="col1" name="Id" />
        <return-property column="col2" name="Name" />
      </return>
    </return>
    call spName(:mySqlP1)
  </sql-query>
</dialect-filter>
<dialect-filter dialect="SQLServer">
  <sql-query name="spForSQLServer" callable="true">
    <query-param name="sqlServerP1" type="int" />
    <return alias="OutType" class="Domain.ResultType, Domain">
      <return class="ResultType">
        <return-property column="col1" name="Id" />
        <return-property column="col2" name="Name" />
      </return>
    </return>
    exec spForSQLServer @sqlServerP1= :sqlServerP1
  </sql-query>
</dialect-filter>
</hibernate-mapping>
  • 1 1 Answer
  • 0 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. Editorial Team
    Editorial Team
    2026-05-21T22:34:02+00:00Added an answer on May 21, 2026 at 10:34 pm

    The easiest way to accomplish something like that would be to put your maps in different assemblies and load maps based on which database you’re operating against.

    Using FluentNHibernate it would look like this:

    bool isSql = true;
    
    var factory = Fluently.Configure()
    ...
    .Mappings(x => isSql ? x.HbmMappingFromAssemblyOf<SqlServerMaps>() : x.HbmMappingFromAssemblyOf<MySqlMaps>())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C++ one might use namespace to keep independent groups working in the same
right now I have the following query in a stored procedure. select * from
I have been using a stored procedure for more than 1.5 years. But I've
I'm searching for strategies one might use to programmatically find files which may be
I'm interested in any common routine/procedures/methods that you might use in you Program.cs when
What is this for and why might I use it?
My iPhone programs frequently contain grouped table views. A typical use might be for
Neither is instantiable. What are the differences, and in what situations might you use
I'm writing a script for IRC and sometimes I might need to use a
Typically I use E_ALL to see anything that PHP might say about my code

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.