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

  • Home
  • SEARCH
  • 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 6180489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:51:06+00:00 2026-05-24T00:51:06+00:00

Say for example, I have the following: public interface IPet { long? Id {

  • 0

Say for example, I have the following:

public interface IPet
{
    long? Id { get; set; }
    string Name { get; set; }
}

public class Cat : IPet
{
    public virtual long? Id { get; set; }
    public virtual string Name { get; set; }
}

public class Dog : IPet
{
    public virtual long? Id { get; set; }
    public virtual string Name { get; set; }
}

And the following mappings:

<class name="Cat" table="`Cat`" >
  <id name="Id" type="long">
    <generator class="identity"/>
  </id>
  <property name="Name"/>
</class>

<class name="Dog" table="`Dog`" >
  <id name="Id" type="long">
    <generator class="identity"/>
  </id>
  <property name="Name"/>
</class>

Now when I do the following:

IList<IPet> pets = session.CreateCriteria<IPet>().List<IPet>();

Because of implicit polymorphism, a nice feature, it returns all cats and dogs. Now consider this:

public class PetShop
{
    public long? Id { get; set; }
    public List<IPet> Pets { get; set; }
}

<class name="PetShop" table="`PetShop`" >
  <id name="Id" type="long">
    <generator class="identity"/>
  </id>
  <property name="Name"/>
  <bag name="Pets"  cascade="all">
    <key column="PetShopId"/>
    <one-to-many class="IPet"/>
  </bag>
</class>

I was hoping this would mean the collection of pets would use implicit polymorphism to fill the collection, but instead I get the error ‘Association references unmapped class: IntefaceCollectionExample.Domain.Entities.IPet’. I could create a mapping and table for IPet witch only included the Id, but this feels unintuitive. I could use union-subclass but would then lose the option to use generator class=”identity”. I could use many-to-any but I feel this would be rather clumsy in this case.

Is there something I’m missing? Is there a way to create a mapping for an interface for IPet but not need a table, and then specify that Cat and Dog implement this. Or is there any better way of acheiving this than the methods I have listed above?

  • 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-24T00:51:06+00:00Added an answer on May 24, 2026 at 12:51 am

    Implicit polymorphism is not supported for one-to-many scenarios

    You can either use an explicit inheritance strategy (i.e. the whole hierarchy must be mapped, starting with the interface), or create a table for the collection and map as many-to-any.

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

Sidebar

Related Questions

Lets say i have the following set of interfaces.... public interface IStart { void
Say suppose I have the following Java code. public class Example { public static
Say for example I have the following string: var testString = Hello, world; And
Say I have a basic interface like the following: public interface IObjectProvider { IEnumerable<IObject>
Say for example I have the following string one two(three) (three) four five and
Say, for example, I have many web applications using the same class library compiled
my application has the following entity: public class User { public virtual int UserID
I have a webpage (say www.example.com/a.asp) .. I am having an iframe in this
I have two websites, let's say they're example.com and anotherexample.net . On anotherexample.net/page.html ,
Say I have a web service http://www.example.com/webservice.pl?q=google which returns text google.com. I need to

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.