Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent NHibernate: How to tell it not to map a base class
    primarykey
    data
    text
    <p>I have been googling and stackoverflowing for the last two hours and couldn't find an answer for my question:</p> <p>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:</p> <pre><code>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; } } </code></pre> <p>Where EntityBase SHOULD NOT be mapped.</p> <p>My NHibernate helper class looks like this:</p> <pre><code>namespace Models.Repository { public class NHibernateHelper { private static string connectionString; private static ISessionFactory sessionFactory; private static FluentConfiguration config; /// &lt;summary&gt; /// Gets a Session for NHibernate. /// &lt;/summary&gt; /// &lt;value&gt;The session factory.&lt;/value&gt; 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; } } /// &lt;summary&gt; /// Add the mappings. /// &lt;/summary&gt; /// &lt;param name="mapConfig"&gt;The map config.&lt;/param&gt; 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&lt;EntityBase&gt;().IgnoreBase&lt;EntityBaseValidation&gt;(); mapConfig.AutoMappings.Add(autoMap); // Merge the mappings mapConfig.MergeMappings(); } /// &lt;summary&gt; /// Opens a session creating a DB connection using the SessionFactory. /// &lt;/summary&gt; /// &lt;returns&gt;&lt;/returns&gt; public static ISession OpenSession() { return SessionFactory.OpenSession(); } /// &lt;summary&gt; /// Closes the NHibernate session. /// &lt;/summary&gt; public static void CloseSession() { SessionFactory.Close(); } } } </code></pre> <p>The error that I'm getting now, is:</p> <blockquote> <p>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</p> </blockquote> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload