I have to entities:
public class User
{
public virtual long Id { get; set; }
public virtual long Name { get; set; }
}
public class Group
{
public virtual long Id { get; set; }
public virtual long Name { get; set; }
}
Mapped as follows:
public class UserMapping : ClassMapping<User>
{
public UserMapping()
{
Table("User");
Id(e => e.Id, t => t.Generator(new IdentityGeneratorDef()));
Property(e => e.Name, map => map.Length(50));
}
}
public class GroupMapping : ClassMapping<Group>
{
public GroupMapping()
{
Table("Group");
Id(e => e.Id, t => t.Generator(new IdentityGeneratorDef()));
Property(e => e.Name, map => map.Length(50));
Set(x => x.Users, set =>
{
set.Table("UserToGroup");
set.Key(key => key.Column("GroupId");
},
re => re.ManyToMany(m => m.Column("UserId")));
}
}
When i delete User entry, from table UserToGroup should be deleted all entries with this user mentioned. When i delete Group entry, from table UserToGroup should be deleted all entries with this group mentioned;
How exactly i need to rewrite my mappings?