Supposed I have 4 tables defined as follows:
Projects: [ Project_Id, Project_Name ]
Vendors: [ Vendor_Id, Vendor_Name ]
Project_Vendors: [ Project_Vendor_Id, Vendor_Id, Project_Id ]
Payments: [ Payment_Id, Project_Vendor_Id, Payment_Amount ]
The relationships should be as follows:
- A Project can have many Vendors associated
- A Vendor can belong to many projects
- Many payments can be made to many vendors of a project (so what makes a payment unique is a project AND a vendor)
I can easily map Project and Vendor objects and their relation using the ProjectVendors lookup table with the following:
public class ProjectMapping : ClassMap<Project> { public ProjectMapping() { Table("Projects"); Id(x => x.Id).Column("Project_Id").GeneratedBy.TriggerIdentity(); HasManyToMany(x => x.Vendors).Table("Project_Vendors") .ParentKeyColumn("Project_Id") .ChildKeyColumn("Vendor_Id") .Cascade.AllDeleteOrphan(); } } My question is, if my classes are defined as follows:
public class Payment { public virtual int? Id { get; set; } public virtual Project Project { get; set; } public virtual Vendor Vendor { get; set; } public virtual double Amount { get; set; } } public class Project { public virtual int? Id { get; set; } public virtual string Name { get; set; } public virtual List<Vendor> Vendors { get; set; } public virtual List<Payment> VendorPayments { get; set; } } How can I map my Project and Payment objects using the lookup table Project_Vendors?