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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:46:38+00:00 2026-05-26T12:46:38+00:00

I have my code working, but I’m getting 2 extra columns in the table/ddl,

  • 0

I have my code working, but I’m getting 2 extra columns in the table/ddl, to represent a Many to Many relationship, ~~but~~ with attributes (scalars) on the relationship.

I am using
1.2.0.712 (FluentNHibernate.dll)
3.1.0.4000 (NHibernate.dll)

Entities:

public partial class Employee
{
    public Employee()
    {
        CommonConstructor();
    }
    private void CommonConstructor()
    {
        this.MyEmployeeToJobTitleMatchLinks = new List<EmployeeToJobTitleMatchLink>();
    }

    public virtual Guid? EmployeeUUID { get; set; }
    public virtual byte[] TheVersionProperty { get; set; }
    public virtual string SSN { get; set; }
    public virtual string LastName { get; set; }
    public virtual string FirstName { get; set; }
    public virtual DateTime CreateDate { get; set; }
    public virtual DateTime HireDate { get; set; }

    public virtual ICollection<EmployeeToJobTitleMatchLink> MyEmployeeToJobTitleMatchLinks { get; set; }
    public virtual void AddJobTitleLink(EmployeeToJobTitleMatchLink link)
    {
        link.TheEmployee = this;
        if (!this.MyEmployeeToJobTitleMatchLinks.Contains(link))
        {
            this.MyEmployeeToJobTitleMatchLinks.Add(link);
        }

        if (!link.TheJobTitle.MyJobTitleToEmployeeMatchLinks.Contains(link))
        {
            link.TheJobTitle.MyJobTitleToEmployeeMatchLinks.Add(link);
        }
    }

    public virtual void RemoveJobTitleLink(EmployeeToJobTitleMatchLink link)
    {
        link.TheEmployee = this;
        if (this.MyEmployeeToJobTitleMatchLinks.Contains(link))
        {
            this.MyEmployeeToJobTitleMatchLinks.Remove(link);
        }

        if (link.TheJobTitle.MyJobTitleToEmployeeMatchLinks.Contains(link))
        {
            link.TheJobTitle.MyJobTitleToEmployeeMatchLinks.Remove(link);
        }
    }
}

public partial class JobTitle
{

    public JobTitle()
    {
        CommonConstructor();
    }
    private void CommonConstructor()
    {
        this.MyJobTitleToEmployeeMatchLinks = new List<EmployeeToJobTitleMatchLink>();
    }

    public virtual Guid? JobTitleUUID { get; set; }
    public virtual byte[] TheVersionProperty { get; set; }
    public virtual string JobTitleName { get; set; }
    public virtual DateTime CreateDate { get; set; }
    public virtual ICollection<EmployeeToJobTitleMatchLink> MyJobTitleToEmployeeMatchLinks { get; set; }
    public virtual void AddEmployeeLink(EmployeeToJobTitleMatchLink link)
    {
        link.TheJobTitle = this;
        if (!this.MyJobTitleToEmployeeMatchLinks.Contains(link))
        {
            this.MyJobTitleToEmployeeMatchLinks.Add(link);
        }

        if (!link.TheEmployee.MyEmployeeToJobTitleMatchLinks.Contains(link))
        {
            link.TheEmployee.MyEmployeeToJobTitleMatchLinks.Add(link);
        }

    }

    public virtual void RemoveEmployeeLink(EmployeeToJobTitleMatchLink link)
    {
        link.TheJobTitle = this;
        if (this.MyJobTitleToEmployeeMatchLinks.Contains(link))
        {
            this.MyJobTitleToEmployeeMatchLinks.Remove(link);
        }

        if (link.TheEmployee.MyEmployeeToJobTitleMatchLinks.Contains(link))
        {
            link.TheEmployee.MyEmployeeToJobTitleMatchLinks.Remove(link);
        }

    }

}

public partial class EmployeeToJobTitleMatchLink
{
    public EmployeeToJobTitleMatchLink()
    {
        //this.Id = Guid.NewGuid(); /* this works in conjuction with <generator class="assigned"></generator>   */
    }

    public virtual Guid? LinkSurrogateUUID { get; set; }

    /*  These are "scalar properties of the ~~relationship~~  */
    public virtual int PriorityRank { get; set; }
    public virtual DateTime JobStartedOnDate { get; set; }

    public virtual Employee TheEmployee { get; set; }
    public virtual JobTitle TheJobTitle { get; set; }
}

Mappings:

public class EmployeeMap : ClassMap<Employee>
{
    public EmployeeMap()
    {
        Id(x => x.EmployeeUUID).GeneratedBy.GuidComb();

        OptimisticLock.Version();
        Version(x => x.TheVersionProperty)
            .Column("MyVersionColumn")
            .Not.Nullable()
            .CustomSqlType("timestamp")
            .Generated.Always();

        Map(x => x.SSN);
        Map(x => x.LastName);
        Map(x => x.FirstName);
        Map(x => x.CreateDate);
        Map(x => x.HireDate);

        HasMany(x => x.MyEmployeeToJobTitleMatchLinks)
            .Inverse()
            .Cascade.All();
    }
}

public class JobTitleMap : ClassMap<JobTitle>
{
    public JobTitleMap()
    {
        Id(x => x.JobTitleUUID).GeneratedBy.GuidComb();

        OptimisticLock.Version();
        Version(x => x.TheVersionProperty)
            .Column("MyVersionColumn")
            .Not.Nullable()
            .CustomSqlType("timestamp")
            .Generated.Always();

        Map(x => x.JobTitleName);
        Map(x => x.CreateDate);
        HasMany(x => x.MyJobTitleToEmployeeMatchLinks)
            .Inverse()
            .Cascade.All();
    }
}

public class EmployeeToJobTitleMatchLinkMap : ClassMap<EmployeeToJobTitleMatchLink>
{
    public EmployeeToJobTitleMatchLinkMap()
    {
        Id(x => x.LinkSurrogateUUID).GeneratedBy.GuidComb();
        Map(x => x.PriorityRank);
        Map(x => x.JobStartedOnDate);
        References(x => x.TheEmployee).Column("TheEmployeeUUID").Not.Nullable();/*Bad naming convention with "The", but left here so it can be seen easily in the DDL*/
        References(x => x.TheJobTitle).Column("TheJobTitleUUID").Not.Nullable();/*Bad naming convention with "The", but left here so it can be seen easily in the DDL*/
    }
}

This works fine, but I’m getting 2 extra (nullable) columns in the ddl. They are marked with asteriks(*) below.

Select * From [dbo].[EmployeeToJobTitleMatchLink]
LinkSurrogateUUID
PriorityRank
JobStartedOnDate
TheEmployeeUUID
TheJobTitleUUID

*Employee_id
*JobTitle_id

I understand this is “by convention”. (The names with the “_id” on them).
But I don’t need these columns. And I need to be able to have customized names.
(TheEmployeeUUID and TheJobTitleUUID in this mock example.)

My end-game is to have:

Select * From [dbo].[EmployeeToJobTitleMatchLink]
LinkSurrogateUUID (UniqueIdentifier, SurrogateKey)
PriorityRank (scalar, int)
JobStartedOnDate (scalar,datetime)
TheEmployeeUUID (UniqueIdentifier, FK back to dbo.Employee.EmployeeUUID )
TheJobTitleUUID (UniqueIdentifier, FK back to dbo.JobTitle.JobTitleUUID )

The attribute(s) on the ~relationship are very important to keep. (PriorityRank and JobStartedOnDate in this mock up example.)

Thanks.
I’m ~so close.

EDIT:

Mappings that work:

public class EmployeeMap : ClassMap<Employee>
{
    public EmployeeMap()
    {
        Id(x => x.EmployeeUUID).GeneratedBy.GuidComb();

        OptimisticLock.Version();
        Version(x => x.TheVersionProperty)
            .Column("MyVersionColumn")
            .Not.Nullable()
            .CustomSqlType("timestamp")
            .Generated.Always();

        Map(x => x.SSN);
        Map(x => x.LastName);
        Map(x => x.FirstName);
        Map(x => x.CreateDate);
        Map(x => x.HireDate);

        HasMany(x => x.MyEmployeeToJobTitleMatchLinks)
            .Inverse()
            .Cascade.All()
            .KeyColumn("TheEmployeeUUID")
            ;

    }
}





public class JobTitleMap : ClassMap<JobTitle>
{
    public JobTitleMap()
    {
        Id(x => x.JobTitleUUID).GeneratedBy.GuidComb();

        OptimisticLock.Version();
        Version(x => x.TheVersionProperty)
            .Column("MyVersionColumn")
            .Not.Nullable()
            .CustomSqlType("timestamp")
            .Generated.Always();


        Map(x => x.JobTitleName);
        Map(x => x.CreateDate);
        HasMany(x => x.MyJobTitleToEmployeeMatchLinks)
            .Inverse()
            .Cascade.All()
            .KeyColumn("TheJobTitleUUID")
        ;   

    }
}



public class EmployeeToJobTitleMatchLinkMap : ClassMap<EmployeeToJobTitleMatchLink>
{

    public EmployeeToJobTitleMatchLinkMap()
    {
        Id(x => x.LinkSurrogateUUID).GeneratedBy.GuidComb();
        Map(x => x.PriorityRank);
        Map(x => x.JobStartedOnDate);

        References(x => x.TheEmployee).Column("TheEmployeeUUID").Not.Nullable();/*Bad naming convention with "The", but left here so it can be seen easily in the DDL*/
        References(x => x.TheJobTitle).Column("TheJobTitleUUID").Not.Nullable();/*Bad naming convention with "The", but left here so it can be seen easily in the DDL*/

    }
}

Thanks Nathan!

PS
One new term I learned while googling/binging myself was

“objectified relationship”

It was in the comments area of this page:
LINK1

In case that page dies sometime in the future, here is that commented pasted in:

It’s called an ‘objectified relationship’ (ref: http://www.orm.net) and in NIAM/ORM it’s typically defined as a relationship which is on itself an entity with attributes. An objectified relationship is always forming at least one m:n relationship.
(From http://weblogs.asp.net/fbouma/ )

  • 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-05-26T12:46:39+00:00Added an answer on May 26, 2026 at 12:46 pm

    I think you need to add a KeyColumn(“key-name”) as part of the HasMany mapping to both your JobTitleMap and EmplyeeMap. This is because fluent-nhibernate is using conventions to create the FK in the EmployeeToJobTitleMatchLink table. Using KeyColumn as part of the HasMay mapping should override the convention.

    Something like the following :-

    public class JobTitleMap : ClassMap<JobTitle> 
    { 
        public JobTitleMap() 
        { 
            Id(x => x.JobTitleUUID).GeneratedBy.GuidComb(); 
    
            OptimisticLock.Version(); 
            Version(x => x.TheVersionProperty) 
                .Column("MyVersionColumn") 
                .Not.Nullable() 
                .CustomSqlType("timestamp") 
                .Generated.Always(); 
    
            Map(x => x.JobTitleName); 
            Map(x => x.CreateDate); 
            HasMany(x => x.MyJobTitleToEmployeeMatchLinks) 
                .Inverse() 
                .Cascade.All()
                **.KeyColumn("TheJobTitleUUID")**
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Django but I seem to have nearly identical code working on
Ok, I have code that is working (posted after this) but before I expand
I have jquery validation code which is working fine in ff but the same
I have a codeigniter code that is working on local Apache installation. But it
I have the following code and it's working (as usual) in everything but IE.
i have tried this code to redirect a php page.but it s not working
I have a jQuery code, but need it working by using Mootools: if (
I have the following code working fine but the problem is that it always
I have this code I been working on but I'm having a hard time
I have this code I am working on but every time I call init

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.