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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:06:18+00:00 2026-06-07T22:06:18+00:00

Nhibernate has a nice feature, which I have discovered coincidentally: public interface IInterface {}

  • 0

Nhibernate has a nice feature, which I have discovered coincidentally:

public interface IInterface {}

public class Impl1 : IInterface {}

public class Impl2 : IInterface {}

ISession session = sf.OpenSession();
session.QueryOver<IInterface>().List();

This will fetch me all Impl1 ans Impl2 objects (in case those classes are mapped). They need not be mapped as SubClassMaps, which leads me to the conclusion that NHibernate resolves the implementing classes all by itself.

Can anyone send me the link to documentation on this one? I know neither the name nor the technical background of this feature…

Thanks in advance!

  • 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-07T22:06:19+00:00Added an answer on June 7, 2026 at 10:06 pm

    Actually, this is just the way NHibernate does inheritance mapping.

    In addition to the usage you described, you also have the ability to i.e. define a child collection on an object, using the base type and put any object of inherited type to the collection. For instance, you could have another entity containing a collection of your IInterface objects:

    public class MyEntity
    {
        public IList<IInterface> MyCollection { get; set; }
    }
    

    Now you could put any object implementing IInterface into MyCollection, and NHibernate will persist them (if mapping is correct):

    Impl1 i1 = new Impl1();
    Impl2 i2 = new Impl2();
    MyEntity entity = new MyEntity();
    entity.MyCollection.Add(i1);
    entity.MyCollection.Add(i2);
    
    session.Save(entity);
    

    However, the actual database usage (generated SQL) depends on the inheritance mapping strategy that you have defined, so get familiar with them first. You can read more in official documentation.

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

Sidebar

Related Questions

I have dictionary which I'm mapping using Fluent NHibernate. The dictionary has a complex
I am using Nhibernate for my ORM. I have a class Control that has
I have an NHibernate detached criteria query which has a couple of inner joins,
How to implement objects (entities) cloning in NHibernate? Each entity class has such properties:
I have a problem with a query using hibernate. The entity class EntityClass has
I have two classes: public class Parent { public virtual long? ID { get;
So with S#arp Architecture , if you have a (say) Dog Entity which has
Does Fluent NHibernate has a simple method for automapping entities? Let's say I have
I'm using Fluent NHibernate to map a a class that has a collection of
NHibernate seems to have some new ways to map entities in code, which is

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.