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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:45:36+00:00 2026-05-23T15:45:36+00:00

I’m converting a previous project from using normal NHibernate hbm.xml mappings to Fluent NHibernate.

  • 0

I’m converting a previous project from using normal NHibernate hbm.xml mappings to Fluent NHibernate. Currently, I’m stuck on what should be one of the last steps to getting this working. I’ve added a derived class for DefaultAutomappingConfiguration to modify my ID naming convention. The string “Id” is appended to the class name:

    public override bool IsId(FluentNHibernate.Member member)
    {
        return member.Name == member.DeclaringType.Name + "Id";
    }

This should make “Agency” have an ID in a field named “AgencyId”. Instead, I’m getting this error:

The entity 'ClassMap`1' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id).
{Name = "ClassMap`1" FullName = "FluentNHibernate.Mapping.ClassMap`1[[BackendDb.Model.Agency, BackendDb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"}

I made a breakpoint on the IsId function to see what’s going on:

{Property: Cache}
{Name = "ClassMap`1" FullName = "FluentNHibernate.Mapping.ClassMap`1[[BackendDb.Model.Agency, BackendDb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"}

What is this? The object is not something I’ve created. Every other object passes through this function fine, and the ones I actually wanted to map are returning the proper value.

My Session factory looks something like this:

var cfg = new MapConfig();
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(m => m.Server(@".\SqlExpress")
    .Database("{some dbname}")
    .TrustedConnection()))
.Mappings(m =>
    m.AutoMappings
        .Add(AutoMap.AssemblyOf<Agency>(cfg))
)
.BuildSessionFactory();

Annoyingly, it seems that this somehow caused the three tables I was testing Fluent NHibernate on in my dev database to be emptied. What the hell?

  • 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-23T15:45:37+00:00Added an answer on May 23, 2026 at 3:45 pm

    The sessionfactory is trying to automap all classes in the assembly that contains your Agency class based on this directive: Add(AutoMap.AssemblyOf<Agency>(cfg)). Since you have an AgencyMap in the assembly andClassMap<> does not have an Id property, FNH is throwing an error.

    If you want to use ClassMap<> configurations, instead of (or in addition to) declaring an automapping configuration, declare a fluent mapping:

    m.FluentMappings.AddFromAssemblyOf<Agency>();
    

    If you don’t need AutoMappings, remove the `.AutoMappings.Add’ directive.

    However, if you want to use AutoMappings, you need to tell FNH what classes you want to map. To handle this, I usually define a marker interface:

    public abstract class Entity : IPersistable
    {
        public virtual int Id { get; set; }
    }
    
    public interface IPersistable
    {
    }
    

    Then, in the class that I derive from DefaultAutomappingConfiguration, I tell FNH to only map the classes that have that interface (you can limit the mapped classes however you see fit):

    public class EntityAutoMappingConfiguration : DefaultAutomappingConfiguration
    {
        public override bool ShouldMap(Type type)
        {
            return type.GetInterfaces().Contains(typeof (IPersistable));
        }
    
    }
    

    To handle the primary key mapping, I create a convention class:

    public class PrimaryKeyNamePlusId : IIdConvention 
    {
        public void Apply(IIdentityInstance instance)
        {
            instance.Column(instance.EntityType.Name+"Id");
        }
    }
    

    Finally, I configure my SessionFactory to use the configuration/convention classes:

     m.AutoMappings.AssemblyOf<Entity>(new EntityAutoMappingConfiguration())
                .IgnoreBase<Entity>()
                .UseOverridesFromAssemblyOf<Entity>()
                .Conventions.AddFromAssemblyOf<Entity>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm parsing an XML file, the creators of it stuck in a bunch social
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.