SubClass mapping and mapping

Mohammad's Avatar

Mohammad

13 Jul, 2010 06:30 PM via web

Hello there,

The following is my classes

public class ObjectRelationship { public virtual long Id {get;set;} public virtual long ParentId {get; set;} public virtual string PropertyClass {get;set;} public virtual string CreatedBy {get;set;} public virtual DateTime CreatedOn {get; set;} }

public class Region: ObjectRelationship {

 public virtual string Code {get;set;}

. . }

public class Contact: ObjectRelationship {

 public virtual string Name {get; set;}
 public virtual string Code {get; set;}
 public virtual string Role {get; set;}

}

public class ObjectRelationshipMap : ClassMap {

  public ObjectRelationshipMap ()
  {
      Id(x => x.Id).GeneratedBy.Sequence("ALL_SEQ");
      Map(x => x.ParentId);
    .
    .
    .
  }

}

public class ContactMap: SubclassMap {

 public ContactMap()
 {
   Table("Contact");
   KeyColumn ("Id");
   Map(x => x.Name);
   .
   .
 }

}

public class RegionMap: SubclassMap {

 public RegionMap()
 {
    Table("Region");
    KeyColumn ("Id");

    Map(x => x.Code);
    .
    .

 }

}

As it shows whenever a Region record is created, an ObjectRelationship record is also created first and the Id is copied into Region "Id" column. The same applies to Contact.

What I want to do is that I want "ParentId" of the Contact associated record in "ObjectRelationship" table refer to "Id" of the Region Record in "ObjectRelationship" table when user creates a region that has at least one contact.

I appreciate it if you let me know if this is possible in as part of one create region task or not.

Thanks in advance,
Mohammad

    Reply to this discussion

    Preview Comments are parsed with Markdown. Help with syntax

    Attached Files

      You can attach files up to 10MB

      Five times two is what?