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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:08:09+00:00 2026-06-16T03:08:09+00:00

I have a generic Repository class that wrap an Nhibernate session: public class Repository<T>{

  • 0

I have a generic Repository class that wrap an Nhibernate session:

public class Repository<T>{

public IQueryable<T> GetAll(){

    return this.Session.Query<T>();
}

}

Despite the fact that I had data in the underlying DB table mapped to entity Foo, calling Repository.GetAll<Foo>() returned an empty enumerable. After much consternation, I found the issue to be that I had forgotten to load my class mapping into the SessionFactory.

I was floored that NHibernate does not throw an exception when attempting to load an entity type for which it has no mapping. This feels like exactly the kind of scenario that should cause NH to fail early and loudly.

Here’s the code that bootstraps NH. Notice the two lines loading the mapping were commented out

 private static Configuration BuildNHibernateConfig(Action<IDbIntegrationConfigurationProperties> dbIntegration)
        {
            var configuration = new Configuration();

            configuration
                .Proxy(p => p.ProxyFactoryFactory<DefaultProxyFactoryFactory>())
                .DataBaseIntegration(db =>
                {

                    db.ConnectionString = connectionString.Value;
                    db.Dialect<MsSql2008Dialect>();

                })
                .AddAssembly(typeof(ActionConfirmation<>).Assembly)
                .SetProperty("show_sql", "true")

                .CurrentSessionContext<LazySessionContext>();

         //   var mappings = GetMappings();
         //   configuration.AddDeserializedMapping(mappings, "Hydra");

            return configuration;
        }

        private static HbmMapping GetMappings()
        {
            var mapper = new ModelMapper();
            mapper.AddMapping<FacilityMap>();
            return mapper.CompileMappingForAllExplicitlyAddedEntities();

        }

Is this normal behavior or I have somehow misconfigured NH? Is there a way to override this behavior?

  • 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-16T03:08:10+00:00Added an answer on June 16, 2026 at 3:08 am

    The LINQ implementation is a wrapper of the Criteria API and this issue has been reported and marked as “won’t fix”. The comment from Fabio Maulo indicates that verifying that the class is mapped was too much of a performance hit.

    This was news to me as well and I at first assumed it was due to LINQ deferred execution.

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

Sidebar

Related Questions

I have a repository class that inherits from a generic implementation: public namespace RepositoryImplementation
I have a generic class called Repository. This class has a function that calls
If I have a generic class like this: public class Repository<T> { public string
I am working with EF generic repository and have this function. public IEnumerable<T> Query(Expression<Func<T,
I have a generic repository as like that public class Repository<T> : IRepository<T> where
I have a Generic class like that : public class Repository<T> {...} And I
I have a generic DAO class that looks like this: public class GenericDaoJpa <T
I have the following generic repository: public class GenericRepository<TEntity> where TEntity : class {
I have this method to get a generic repository out of a dictionary: public
I have generic type that looks like: public class GenericClass<T, U> where T :

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.