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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:22:37+00:00 2026-05-13T01:22:37+00:00

I have been googling and stackoverflowing for the last two hours and couldn’t find

  • 0

I have been googling and stackoverflowing for the last two hours and couldn’t find an answer for my question:

I’m using ASP.NET MVC and NHibernate and all I’m trying to do is to manually map my entities without mapping its base class. I’m using the following convention:

public class Car : EntityBase
{
    public virtual User User { get; set; }
    public virtual string PlateNumber { get; set; }
    public virtual string Make { get; set; }
    public virtual string Model { get; set; }
    public virtual int Year { get; set; }
    public virtual string Color { get; set; }
    public virtual string Insurer { get; set; }
    public virtual string PolicyHolder { get; set; }
}

Where EntityBase SHOULD NOT be mapped.

My NHibernate helper class looks like this:

namespace Models.Repository
{
    public class NHibernateHelper
    {
        private static string connectionString;
        private static ISessionFactory sessionFactory;
        private static FluentConfiguration config;

        /// <summary>
        /// Gets a Session for NHibernate.
        /// </summary>
        /// <value>The session factory.</value>
        private static ISessionFactory SessionFactory
        {
            get
            {
                if (sessionFactory == null)
                {
                    // Get the connection string
                    connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
                    // Build the configuration
                    config = Fluently.Configure().Database(PostgreSQLConfiguration.PostgreSQL82.ConnectionString(connectionString));
                    // Add the mappings
                    config.Mappings(AddMappings);
                    // Build the session factory
                    sessionFactory = config.BuildSessionFactory();
                }
                return sessionFactory;
            }
        }

        /// <summary>
        /// Add the mappings.
        /// </summary>
        /// <param name="mapConfig">The map config.</param>
        private static void AddMappings(MappingConfiguration mapConfig)
        {
            // Load the assembly where the entities live
            Assembly assembly = Assembly.Load("myProject");
            mapConfig.FluentMappings.AddFromAssembly(assembly);
            // Ignore base types
            var autoMap = AutoMap.Assembly(assembly).IgnoreBase<EntityBase>().IgnoreBase<EntityBaseValidation>();
            mapConfig.AutoMappings.Add(autoMap);
            // Merge the mappings
            mapConfig.MergeMappings();
        }

        /// <summary>
        /// Opens a session creating a DB connection using the SessionFactory.
        /// </summary>
        /// <returns></returns>
        public static ISession OpenSession()
        {
            return SessionFactory.OpenSession();
        }

        /// <summary>
        /// Closes the NHibernate session.
        /// </summary>
        public static void CloseSession()
        {
            SessionFactory.Close();
        }
    }
}

The error that I’m getting now, is:

System.ArgumentException: The type or
method has 2 generic parameter(s), but
1 generic argument(s) were provided. A
generic argument must be provided for
each generic parameter

This happens when I try to add the mappings. Is there any other way to manually map your entities and tell NHibernate not to map a base class?

  • 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-13T01:22:37+00:00Added an answer on May 13, 2026 at 1:22 am

    If you don’t want to automap a class, I would recommend using IAutoMappingOverride<T>. I don’t about your database, but it might look like:

    public class CarOverride : IAutoMappingOverride<Car>
    {
    
        public void Override(AutoMapping<Car> mapping){
            mapping.Id( x => x.Id, "CarId")
              .UnsavedValue(0)
              .GeneratedBy.Identity();
    
    
            mapping.References(x => x.User, "UserId").Not.Nullable();
    
            mapping.Map(x => x.PlateNumber, "PlateNumber");
            // other properties
        }
    }
    

    Assuming you keep these maps centrally located, you could then load them on your autoMap:

    var autoMap = AutoMap.Assembly(assembly).IgnoreBase<EntityBase>().IgnoreBase<EntityBaseValidation>()
                    .UseOverridesFromAssemblyOf<CarOverride>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been googling about this problem and couldn't find any good websites.... I
So i have been googling/binging trying to find an answer on this but drawing
I have been googling a lot and I couldn't find if this even exists
I have been googling for hours and cannot find any solid answers but lots
I have been googling for hours looking for something to handle my situation. I
Have been working on this question for a couple hours and have come close
I have been googling and reading various posts around the net and I've tried:
I have been googling this question, but so far nothing found. Is there some
I have been googling a lot about this, but I can't find a specific
I have been googling a bit, but did not find what i was looking

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.