Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8967013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:09:05+00:00 2026-06-15T17:09:05+00:00

Supposed I have 4 tables defined as follows: Projects : [ Project_Id, Project_Name ]

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:09:06+00:00Added an answer on June 15, 2026 at 5:09 pm

    Not directly possible without mapping the Project_Vendors table because NHibernate has to know where the id to reference comes from. You might be able to fake it but i would advice against it.

    class ProjectVendorPair
    {
        public virtual int Id { get; set; } 
        public virtual Project Project { get; set; }
        public virtual Vendor Vendor { get; set; }
    }
    
    // in PaymentMap
    References(x => x.Owner, "Project_Vendor_Id");
    

    Or you change the database Structure:

    • get rid of column Project_Vendor_Id
    • have columns Project_Id and Vendor_Id in Payment table
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have my SqlDataSource with a SelectQuery defined as follows: SELECT * FROM
I have two tables defined for actual and expected with exactly the same schema.
Suppose I have a database defined as: // Baked goods vendors var vendor =
Does the Django ORM have a construct defined that generates tables from each row
I have two functions defined that are basically supposed to get a value from
Suppose I have two tables, - emp(empId number(1),empName varchar2(50)) and - manager(manId number(5),managerName varchar2(100))
Suppose we have two tables Foo and Bar. I have an association table Foo_Bar
Suppose I have two tables Main and Other like the following: Main +----------+-----------------------------------+ |
Suppose I have 2 tables in a database. eg: Dog & Boss This is
Suppose I have two tables that are linked (one has a foreign key to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.