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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:29:14+00:00 2026-06-17T00:29:14+00:00

I’m having a problem with nHibernate: If an entity inherits from a base entity,

  • 0

I’m having a problem with nHibernate: If an entity inherits from a base entity, then this child entity cannot be referenced by another entity.


I have an inheritance hierarchy in my database as follows:

  • VideoFeed IS A VisualFeed
  • VideoFeed has many PlaylistAssignment

Here’s the (paraphrased) SQL definition

create table VisualFeed
(
    id BIGINT NOT NULL  -- Primary key
)

create table VideoFeed
(
   id BIGINT NOT NULL   -- Primary key, foriegn key references VisualFeed
)

create table PlaylistAssignment
(
   id BIGINT NOT NULL,   -- Primary key
   VideoFeed_Id BIGINT NOT NULL   -- Foreign key to VideoFeed
)

And the class definitions

public class VisualFeed 
{
    public virtual long? Id { get; set; }
}

public class VideoFeed : VisualFeed
{
    public virtual ISet<PlaylistAssignment> PlaylistAssignments { get; set; }
}

public class PlaylistAssignment
{
    public virtual long? Id { get; set; }
    public virtual VideoFeed VideoFeed { get; set; }
}

Here’s the mapping code for VisualFeed (the parent class):

public static void Map(ModelMapper mapper)
{
mapper.Class<DATMedia.CMS.EntityLibrary.Entities.VisualFeed>(
        classMapper =>
        {
            classMapper.Table("cms_VisualFeed");
            classMapper.Id(
                            visualFeed => visualFeed.Id,
                            idMapper =>
                            {
                                idMapper.Column("Id");
                                idMapper.Generator(Generators.HighLow,
                                                    generatorMapper =>
                                                    {
                                                        generatorMapper.Params(

                                                            new
                                                            {
                                                                max_lo = 256,
                                                                column = "NextHi",
                                                                where = "TableName='VisualFeed'"
                                                            }
                                                        );
                                                    }
                                );
                            }
            );
    });
}

Here’s the mapping code for VideoFeed:

public static void Map(ModelMapper mapper)
{
    mapper.JoinedSubclass<DATMedia.CMS.EntityLibrary.Entities.VideoFeed>(
            joinedSubClassMapper =>
            {
                joinedSubClassMapper.Table("cms_VideoFeed");
                joinedSubClassMapper.Key(keyMapper =>
                    {
                        keyMapper.Column("Id");
                    }
                );


                joinedSubClassMapper.Set(
                    playerGroup => playerGroup.PlaylistAssignments,
                    setPropertiesMapper =>
                    {
                        setPropertiesMapper.Key(
                                keyMapper =>
                                {
                                    keyMapper.Column("VideoFeed_Id");
                                    keyMapper.PropertyRef(videoFeed => videoFeed.Id);
                                }
                            );
                        setPropertiesMapper.Cascade(Cascade.All | Cascade.DeleteOrphans);
                        setPropertiesMapper.Inverse(true);
                        setPropertiesMapper.OrderBy(playlistAssignment => playlistAssignment.AssignmentRank);
                    },
                    collectionElementRelation =>
                    {
                        collectionElementRelation.OneToMany();
                    }
                );    
            }
            );
}

And the mapping code for `PlaylistAssignment’:

public static void Map(ModelMapper mapper)
{

    mapper.Class<DATMedia.CMS.EntityLibrary.Entities.PlaylistAssignment>(
            classMapper =>
            {
                classMapper.Table("cms_PlaylistAssignment");
                classMapper.Id(
                    playlistAssignment => playlistAssignment.Id,
                    idMapper =>
                    {
                        idMapper.Generator(Generators.Identity);
                    }

                    );

                classMapper.ManyToOne(
                        pa => pa.VideoFeed,
                        manyToOneMapper =>
                        {
                            manyToOneMapper.Column("VideoFeed_Id");
                            manyToOneMapper.Lazy(LazyRelation.Proxy);
                        }
                    );
           });
 };

An exception gets thrown when when calling ModelMapper.CompileMappingForAllExplicitlyAddedEntities.

The exception is thrown inside nHibernate code, in the file KeyMapper.cs:

public void PropertyRef(MemberInfo property)
{
   if (property == null)
   {
       mapping.propertyref = null;
       return;
   }
   if (!ownerEntityType.Equals(property.DeclaringType) && !ownerEntityType.Equals(property.ReflectedType))
   {
    throw new ArgumentOutOfRangeException("property", "Can't reference a property of another entity.");
   }
   mapping.propertyref = property.Name;
}

ownerEntityType equals “VideoFeed”, and both ReflectedType and DeclaringType equals “VisualFeed” (the parent class name). Even though this is all correct, the ArgumentOutOfRangeException gets thrown.


Can anyone think of a workaround?


Later Edit This problem was caused by explicit reference calls to setPropertiesMapper. It was actually on a different child class which I had ommitted from the question (in a misguided attempt at simplifiying the problem).

The actual culprit is in the mapping to ‘cms_VisualFeedAssignment’ below:

        mapper.Class<DATMedia.CMS.EntityLibrary.Entities.VisualFeed>(
                classMapper =>
                {
                    classMapper.Table("cms_VisualFeed");
                    classMapper.Id(
                                    visualFeed => visualFeed.Id,
                                    idMapper =>
                                    {
                                        idMapper.Column("Id");
                                        idMapper.Generator(Generators.HighLow,
                                                            generatorMapper =>
                                                            {
                                                                generatorMapper.Params(

                                                                    new
                                                                    {
                                                                        max_lo = 256,
                                                                        column = "NextHi",
                                                                        where = "TableName='VisualFeed'"
                                                                    }
                                                                );
                                                            }
                                        );
                                    }
                    );
                 classMapper.Set<DATMedia.CMS.EntityLibrary.Entities.VisualFeedAssignment>(
                                    visualFeed => visualFeed.Assignments,
                                    bagPropertiesMapper =>
                                    {
                                        bagPropertiesMapper.Inverse(true);
                                        bagPropertiesMapper.Lazy(CollectionLazy.Lazy);
                                        bagPropertiesMapper.Key(
                                            keyMapper =>
                                            {
                                                keyMapper.Column("VisualFeed_Id");
                                                //keyMapper.PropertyRef<long?>(visualFeed => visualFeed.Id);
                                            }
                                        );
                                        bagPropertiesMapper.Table("cms_VisualFeedAssignment");
                                    },
                                    collectionElementRelation =>
                                    {
                                        collectionElementRelation.OneToMany();
                                    }
                                );
                        }
                    );
            }

When I commented out the PropertyRef call, it worked.

  • 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-17T00:29:16+00:00Added an answer on June 17, 2026 at 12:29 am

    You don’t need this line:

    keyMapper.PropertyRef(videoFeed => videoFeed.Id);
    

    The VideoFeed.Id would automatically be referenced. Try removing that line, it should work.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.