In my code I have an three main entities: 1. Company 2. Staff 3. Position
A staff can have several positions in various companies.
I want to retrieve all staff associated to a specific company.
In code I would do something like:
public partial class Company
{
public virtual IEnumerable<Position> Positions { get; protected set; }
public virtual IEnumerable<Staff> Staffs
{
get { return Positions.Select(x => x.Staff); }
}
}
class CompanyMap : ClassMap<Company>
{
public CompanyMap()
{
Id(x => x.Id)
.Column("CompanyId")
.GeneratedBy.Identity();
Map(x => x.Name)
.Not.Nullable();
HasMany(x => x.Positions)
.KeyColumn("CompanyId")
.AsBag();
}
}
Pb: In this solutionm I will load all positions associated to a company and then all staff associated to each position... In terms of performance it's not very good i guess...
I'm pretty sure there is a better way to perform this join directly in the CompanyMap class.
Could you help me to do that?
Thank you, Sebastien