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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:48:43+00:00 2026-05-24T13:48:43+00:00

To centralize some of my logic for each FluentNHibernate class mapping (specifically for mapping

  • 0

To centralize some of my logic for each FluentNHibernate class mapping (specifically for mapping auditing properties and the actual primary ID), I’ve got a base ClassMap called AuditedEntityClassMap which is something like the following:

public class AuditedEntityClassMap<TEntity, T> : ClassMap<TEntity> where TEntity : AuditedPersistentObject<T>
{
    public AuditedEntityClassMap()
    {
        Cache.ReadWrite();
        DynamicUpdate();
        ApplyId();
        this.ChangeAuditInfo();
    }

    protected virtual void ApplyId()
    {
            if (typeof(T) == typeof(int))
                map.Id(x => x.Id).GeneratedBy.HiLo(HiLoConstants.NHibernateHiLoTable, HiLoConstants.NHibernateHiLoColumn, HiLoConstants.NHibernateHiLoMaxLo);
            else if (typeof(T) == typeof(Guid))
                map.Id(x => x.Id).GeneratedBy.GuidComb();
            else
                throw new InvalidIdTypeInClassMappingException("Invalid type set in class mapping: " + typeof(T));
    }
}

My question is that the type checking of the generic in order to determine the type of NHibernate generator mapping that should be used for it smells and I’m wondering if there’s a better way of dealing with it.

  1. The generic type for my domain entities’ IDs is used throughout and works great everywhere else (and it’s used extensively).
  2. I’d prefer not to have to define the ID mapping in every entity’s ClassMap if I can avoid it. If this is the only way to do so, I’ll live with it.

Thoughts and suggestions?

  • 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-24T13:48:43+00:00Added an answer on May 24, 2026 at 1:48 pm

    Looks like there’s nothing better than what I’ve got now.

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

Sidebar

Related Questions

I am trying to centralize Core Data calls for each Core Data entity into
When writing TSQL stored procedures I find myself wanting to centralize / normalize some
I've got some JavaScript in an ASP.NET page that looks like this: var list
To release my centralized webapp, I COULD have a vhost pointed to some directory
So, I'm thinking of having the following centralized setup with Git (each of these
I am doing a website (WIP). I encountered some CSS problems, hope you guys
How do I have in each *.pas file it's version, incrementing on each save
I've been reviewing Windows Azure platform for some time, and can't find answer to
Using CakePHP, I am finding that I'm duplicating some code between controller actions. I
There was a very interesting discussion on LosTechies regarding AutoMapper(an argument for/against 2-way mapping).

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.