views:

112

answers:

2

this is my db: tblGroups: GroupID GroupName

tblMembersInGroup GroupID MemberID Rank

tblMembers MemberID Name

this is my Model:

class group 
{
  int groupid
  string name
  List<EnlistedMembers> myMembers;

}

class EnlistedMebmers
{
  Member myMember;
  int Rank;
}

class Member
{  
  int MemberID
  string Name
}

I am not sure how to map this in FNH, as the Members class has no object that tells FNH who is the father.

I think the group mapping is obvious:

 Table(tblGroup);
    Id(x => x.groupid, "GroupID').GeneratedBy.Identity();
    Map(x => x.name, "GroupName");
    HasMany(x => x.myMembers).AsList().Inverse().Cascade.All();

What's next ?

how do I map enlistedmembers, with no identity object? and no group object ? but with the extra rank data. the db has all the data, I need a way to create the classes right...

Thanks,

Dani

A: 

Is there a reason you need to map EnlistedMembers? If not, you could map Group.MyMembers like this:

HasManyToMany(z => z.MyMembers)
                .AsList()
                .Cascade.All()
                .Table("tblMembersInGroup")
                .ParentKeyColumn("GroupId")
                .ChildKeyColumn("MemberId");
mxmissile
But the EnlistedMember has a rank field - which needs to carry some more data ! that what makes the problem...
Dani
Gotcha, missed that member. Can you add EnlistedMember.Group? And Member.Enlisted?
mxmissile
I think I can, it will make it easier. I though there is a possibility to map without them (as from data model point of you - these objects has all that I need, and the addition will only consume memory, not to be used). But.. I can't find a decent example for many-to-many mapping with extra data involved...
Dani
A: 

I suspect this may be a square peg for a round hole, but I'd look into SubClassing.

public class MemberMap : ClassMap<Member>
{
  public MemberMap()
  {
    Table("tblMembers");
    Id(x => x.MemberID);
    Map(x => x.Name);
  }
}

public class EnlistedMembersMap : SubclassMap<EnlistedMembers>
{
  public EnlistedMembersMap()
  {
    Table("tblMembersInGroup");
    Map(x => x.Rank);
  }
}

You'll need to make EnlistedMembers inherit from Member. I'm also pretty sure it's going to bark about the composite key you have going in tblMembersInGroup. I don't have an answer for that... yet.

ddc0660
EnlistedMember can't inherit from member, asa member can be associated with a few objects of enlisted member(I'm a member in 3 groups, in each group I have different rank) - I don't want to create 3 enlisted member object and tell them my name, rather create one member with name (and all other details the hase been omitted from the question) and plug it into enlistedmember object with rank....
Dani

related questions