Property ignored when automapping inheritance chain

Original Post trondaron's Avatar

trondaron

31 Mar, 2010 11:36 PM via web

I've attached a cut down version of my application based on the Sharp Architecture template. There is a single unit test on SharpTest.Tests.dll that show my issue. The unit test itself passes, but the output of the schema is (imo) not correct.
Basically:
ClassC inherits from SharpArch.Core.DomainModel.Entity
ClassA and ClassB inherit from ClassC
ClassA and ClassB each have a property name "PropertyName"

The unit test schema output is as follow:

create table ClassCs (
    Id INTEGER not null,
   WeAllGotOne TEXT,
   primary key (Id)
)
create table ClassA (
    ClassCFk INTEGER not null,
   ClassAName TEXT,
   PropertyName TEXT,
   primary key (ClassCFk)
)
create table ClassB (
    ClassCFk INTEGER not null,
   ClassBName TEXT,
   primary key (ClassCFk)
)

Under the table creation for ClassB there should be a definition of:

   PropertyName TEXT,

I can force it to appear by explicitly mapping it, but I'd like to know if I'm doing something wrong in the inheritance structure that causes this.

  1. 2 Posted by Dan Kent on 09 Apr, 2010 12:31 PM

    Dan Kent's Avatar

    I think I have hit the same problem - I found this post when googling for information on it.

    It seems that when multiple classes that inherit from a common base have a property with the same name, the property is sometimes ignored by the automapper on one or more of the classes.

    This means that the column is not created in the database when doing schema generation.

    I haven't been able to get to the bottom of what determines which class the property gets ignored on.

    A workaround is to give the properties different names in the classes but that's obviously not ideal - it should be perfectly fine to have subclasses that have properties that happen to have the same name.

  2. 3 Posted by Dan Kent on 14 Apr, 2010 10:28 AM

    Dan Kent's Avatar

    I've found that there is more of a problem with this when using interfaces.

    For example, in the system I am building I have an IAudited interface:

    public interface IAudited
    {
        User CreatedBy { get; set; }
        DateTime CreatedAt { get; set; }
        User UpdatedBy { get; set; }
        DateTime UpdatedAt { get; set; }
    }
    

    Which is then used in an IPreUpdateEventListener and IPreInsertEventListener to get NHibernate to set the values when an object that supports it is persisted.

    This worked great for the first class I applied it to but as soon as I applied it to another class in the same hierarchy, the database columns disappeared from the first class. There are no errors - the properties are simply ignored when hydrating or dehydrating the objects.

    The property renaming work around won't work in this case, so it looks like I will have to add an override for each class that supports the IAudited interface :(

  3. 4 Posted by Dan Kent on 19 Apr, 2010 10:50 AM

    Dan Kent's Avatar

    It looks like this issue has been fixed recently - downloading the most recent build seems to have resolved it.

    Well done the Fluent NHibernate team!

  4. James Gregory resolved this discussion on 16 May, 2010 05:36 PM.

Comments are currently closed for this discussion. You can start a new one.

Recent Discussions

05 Jul, 2010 10:29 PM
05 Jul, 2010 12:45 PM
05 Jul, 2010 12:42 PM
05 Jul, 2010 12:17 PM
05 Jul, 2010 12:12 PM

 

03 Jul, 2010 12:26 AM
02 Jul, 2010 02:17 PM
02 Jul, 2010 08:18 AM
02 Jul, 2010 12:20 AM
01 Jul, 2010 10:14 PM