How to map SubClasses with Composite Keys

Original Post Matt Trinder's Avatar

Matt Trinder

12 Apr, 2010 09:33 PM via web

Hi

I'm trying to create a table-per-entity mapping for a 2 tables with a composite primary key - how do I map the sub-class...? I found a issue that said that this had been fixed in the 1.0 version, but I can't figure out how to do it...!

Cheers

Matt

  1. 2 Posted by asa.jones on 27 Apr, 2010 10:42 AM

    asa.jones's Avatar

    I think i have managed this using the "SubclassMap" class

    I make sure that my business objects are inherited correctly, therefore I have a Person class which inherits from the Party class.
    You specify the "KeyColumn" in the Subclass Map.
    For composites you need to repeat the KEYClumn method for each field.

    I've experience some issues with this in the past where it appears the order in which you add the Columns is relevant

    The two maps are included below.

    public class PersonRoleMap: SubclassMap<PersonRole>
    {
        public PersonRoleMap()
        {
            Table("[Person Role]");
            KeyColumn("PartyID");
            KeyColumn("RoleTypeID");
        }
    }
    

    public sealed class PartyRoleMap: ClassMap

    {
        public PartyRoleMap()
        {
            Table("PartyRole");
             CompositeId()
                .KeyReference(x => x.Party, "PartyID")
                .KeyReference(x => x.RoleType, "RoleTypeID");
         ///...
    
          }
    }
    

    Hope this helps

  2. James Gregory resolved this discussion on 16 May, 2010 05:31 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