Thanks!
But I still have a question ;)
Given these 2 entities, linked with a double many-to-many relationship:
public class Possession : BaseEntity
{
private readonly Iesi.Collections.Generic.ISet<PlayerInTeam>
attackingPlayers = new Iesi.Collections.Generic.HashedSet<PlayerInTeam>();
private readonly Iesi.Collections.Generic.ISet<PlayerInTeam>
defendingPlayers = new Iesi.Collections.Generic.HashedSet<PlayerInTeam>();
public Possession()
{
}
public IEnumerable<PlayerInTeam> AttackingPlayers
{
get { return attackingPlayers; }
}
public IEnumerable<PlayerInTeam> DefendingPlayers
{
get { return defendingPlayers; }
}
}
public class PlayerInTeam : BaseEntity
{
private readonly Iesi.Collections.Generic.ISet<Possession>
attackingPossessions = new HashedSet<Possession>();
private readonly Iesi.Collections.Generic.ISet<Possession>
defendingPossessions = new HashedSet<Possession>();
public PlayerInTeam()
{
}
public IEnumerable<Possession> AttackingPossessions { get { return
attackingPossessions; } }
public IEnumerable<Possession> DefendingPossessions { get { return
defendingPossessions; } }
}
I have the following mapping:
mapper.Class<PlayerInTeam>(cm =>
{
cm.ManyToOne(pit => pit.Position, mtom => mtom.NotNullable(false));
cm.Set(pit => pit.AttackingPossessions, set =>
set.Table("PossessionAttackingPlayers"), rel => rel.ManyToMany(map =>
map.Column("PossessionId")));
cm.Set(pit => pit.AttackingPossessions, set => set.Inverse(false));
cm.Set(pit => pit.AttackingPossessions, set =>
set.Cascade(Cascade.Persist));
cm.Set(pit => pit.DefendingPossessions, set =>
set.Table("PossessionDefendingPlayers"), rel => rel.ManyToMany(map =>
map.Column("PossessionId")));
cm.Set(pit => pit.DefendingPossessions, set => set.Inverse(false));
cm.Set(pit => pit.DefendingPossessions, set =>
set.Cascade(Cascade.Persist));
});
mapper.Class<Possession>(cm =>
{
cm.ManyToOne(p => p.Match, pm => pm.Access(Accessor.Field));
cm.ManyToOne(p => p.StartAction, pm => pm.Access(Accessor.Field));
cm.ManyToOne(p => p.EndAction, pm => pm.Access(Accessor.Field));
cm.ManyToOne(p => p.EndAction, pm => pm.NotNullable(false));
cm.Set(p => p.AttackingPlayers, set =>
set.Table("PossessionAttackingPlayers"), rel => rel.ManyToMany(map =>
map.Column("PlayerInTeamId")));
cm.Set(p => p.DefendingPlayers, set =>
set.Table("PossessionDefendingPlayers"), rel => rel.ManyToMany(map =>
map.Column("PlayerInTeamId")));
});
This gives the following database schema:
create table PlayerInTeam (
PlayerInTeamId INT IDENTITY NOT NULL,
primary key (PlayerInTeamId)
)
create table PossessionAttackingPlayers (
PlayerInTeamId INT not null,
PossessionId INT not null,
primary key (PossessionId, PlayerInTeamId)
)
create table PossessionDefendingPlayers (
PlayerInTeamId INT not null,
PossessionId INT not null,
primary key (PossessionId, PlayerInTeamId)
)
create table Possession (
PossessionId INT IDENTITY NOT NULL,
primary key (PossessionId)
)
Is it possible to use only 1 relation table, with a boolean discriminant to
determine if the relationship is about Attack or Defense?
Thanks in advance
Mike
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.