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 8205591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:18:23+00:00 2026-06-07T08:18:23+00:00

Is there a way to specify a table to use for Hi-Lo values, with

  • 0

Is there a way to specify a table to use for Hi-Lo values, with each entity having a per-row entry, via a convention (while still having nHibernate create the table structure for you)? I would like to replicate what Phil Haydon blogged about here, but without having to manually manage the table. As it stands, migrating his row-per-table code to its own convention will work only if you’ve already created the appropriate entries for ‘TableKey’ in the table already.

Alternatively, is this possible via the XML mappings?

And if all else fails, is the only other appropriate option to use a custom generator, a la this post?

  • 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-06-07T08:18:24+00:00Added an answer on June 7, 2026 at 8:18 am

    Fabio Maulo talked about this in one of his mapping-by-code posts.

    Mapping by code example:

    mapper.BeforeMapClass += (mi, type, map) =>
        map.Id(idmap => idmap.Generator(Generators.HighLow,
            gmap => gmap.Params(new
            {
                table = "NextHighValues",
                column = "NextHigh",
                max_lo = 100,
                where = string.Format(
                    "EntityName = '{0}'", type.Name.ToLowerInvariant())
            })));
    

    For FluentNHibernate, you could do something like:

    public class PrimaryKeyConvention : IIdConvention
    {
        public void Apply(IIdentityInstance instance)
        {
            var type = instance.EntityType.Name;
            instance.Column(type + "Id");
            instance.GeneratedBy.HiLo(type, "NextHigh", "100", 
                x => x.AddParam("where", String.Format("EntityName = '{0}'", type));
        }
    }
    

    Also, Fabio explained how you could use IAuxiliaryDatabaseObject to create Hi-Lo script.

    private static IAuxiliaryDatabaseObject CreateHighLowScript(
        IModelInspector inspector, IEnumerable<Type> entities)
    {
        var script = new StringBuilder(3072);
        script.AppendLine("DELETE FROM NextHighValues;");
        script.AppendLine(
            "ALTER TABLE NextHighValues ADD EntityName VARCHAR(128) NOT NULL;");
        script.AppendLine(
            "CREATE NONCLUSTERED INDEX IdxNextHighValuesEntity ON NextHighValues " 
            + "(EntityName ASC);");
        script.AppendLine("GO");
    
        foreach (var entity in entities.Where(x => inspector.IsRootEntity(x)))
        {
            script.AppendLine(string.Format(
             "INSERT INTO [NextHighValues] (EntityName, NextHigh) VALUES ('{0}',1);",
             entity.Name.ToLowerInvariant()));
        }
    
        return new SimpleAuxiliaryDatabaseObject(
            script.ToString(), null, new HashedSet<string> {
               typeof(MsSql2005Dialect).FullName, typeof(MsSql2008Dialect).FullName 
            });
    }
    

    You would use it like this:

    configuration.AddAuxiliaryDatabaseObject(CreateHighLowScript(
        modelInspector, Assembly.GetExecutingAssembly().GetExportedTypes()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to specify distinct sequences for each table in Hibernate, if
Is there any way to specify table column width as is. In other words,
Is there a way to specify which object to use for global when invoking
Is there a way to specify the maximum recursion level for recursive diff diff
Is there a way to specify the root directory at runtime within a program's
Is there any way to specify that a function should be called when a
Is there any way to specify a width when doing :vsplit? Also, is there
Is there a way to specify which namespace includes should be automatically added any
Is there a way to specify in a data connection or the LinqToSql Designer
Is there a way to specify pretty-print-like formatting around HTML tags? I want to

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.