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 4013500
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:22:45+00:00 2026-05-20T09:22:45+00:00

I have ran into quite an interesting mapping scenario. I have two entities (

  • 0

I have ran into quite an interesting mapping scenario. I have two entities (Task and ProjectEmployeeFile) that has two identical foreign keys (ProjectId and EmployeeId).

I am trying to find an elegant way to map a Tasks property to the ProjectEmployeeFile entity.

I think that the solution for one foreign key relationship would be by using a ternary association but I have no idea how to project this into multiple foreign keys.

I am using fluent nhibernate but if solving this issue with classic hbm files is the way to go I have no problem with mapping those classes manually.

Any help would be greatly appreciated.

I have drawn a basic diagram to try to illustrate the scenario:

A basic diagram to try to illustrate my scenario

I have mixed property names with database column names freely here but I think the general idea is clear.

update

In order to clarify the domain model, here is the current entities and mappings, stripped to the minimum:

    public class Task
    {
        public virtual int Id { get; private set; }
        public virtual Project Project { get; set; }
        public virtual Employee Employee { get; set; }
    }

    public class ProjectEmployeeFile
    {
        public virtual int Id { get; private set; }
        public virtual Project Project { get; set; }
        public virtual Employee Employee { get; set; }
    }

    public class Project
    {
        public virtual int Id { get; private set; }
        public virtual IList<Task> Tasks { get; set; }

    }

    public class Employee
    {
        public virtual int Id { get; private set; }
        public virtual IList<Task> Tasks { get; set; }
    }


public class TaskMap : ClassMap<Task>
{
    public TaskMap()
    {
        Table("Tasks");
        Id(x => x.Id);
        References(x => x.Project).Column("ProjectId");
        References(x => x.Employee).Column("EmployeeId");
    }
}

public class ProjectEmployeeFileMap : ClassMap<ProjectEmployeeFile>
{
    public ProjectEmployeeFileMap()
    {
        Table("ProjectEmployeeFiles");
        Id(x => x.Id);
        References(x => x.Project).Column("ProjectId");
        References(x => x.Employee).Column("EmployeeId");
    }
}
  • 1 1 Answer
  • 2 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-05-20T09:22:46+00:00Added an answer on May 20, 2026 at 9:22 am

    This mapping might work (I haven’t tested it):

    <class name="ProjectEmployeeFile">
      ...
      <bag name="Tasks" inverse="true">
        <key column="ProjectId" property-ref="Project"/>
        <key column="EmployeeId" property-ref="Employee"/>
        <one-to-many class="Task"/>
      </bag>
    </class>
    

    I don’t know if it’s possible to do it with fluent, but you can mix them anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into an interesting dilemma today. I have a function that handles information
I have ran into an interesting issue while trying to create a more usable
I ran into this issue quite a few times. Let's say I have a
I ran into an interesting problem yesterday and while the fix was quite simple,
Ran into an issue with a class; I have a class that looks like:
Currently developing a PHP framework and have ran into my first problem. I need
I'm currently getting to grips with mod_rewrite and have ran into a stumbling block
I'm building a module installer for my CMS and i have ran into a
I am learning JQuery, and I have ran into an odd issue. I made
I am fairly new to C++, but i have ran into an issue which

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.