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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:30:38+00:00 2026-05-13T18:30:38+00:00

I’m polling mulitple systems (domains) for security info so I’m dealing domainUsers and their

  • 0

I’m polling mulitple systems (domains) for security info so I’m dealing domainUsers and their roles. I’ve got my entities setup as show below, but I’m having trouble setting up the domainUser.HasMany relationship in the AutoMapper override.

You’ll notice that I don’t have domainUser.DomainUserId and role.RoleId which make this much more simple (no compositeIds.) I’ve avoided those fields because I’ve already got a natural composite key and it will be populate when I pull this data from the downstream domain. If I add those artificial keys, I’ll have to pre-fetch their values before I call session.Merge(domainUser). I’m trying to avoid doing that.

The entity objects are obvious (I hope) but here is what I’ve got.

public class DomainUser 
   {
      public virtual int Domain_Id { get; set; }
      public virtual string DomainUserLogin { get; set; }
      public virtual string EmployeeId { get; set; }

      // extra field removed for breviety


      public DomainUser()
      {
         this.Roles = new List<DomainUserRole>();
      }

      public virtual void AddRole(DomainUserRole role)
      {
         role.DomainUser = this;
         this.Roles.Add(role);
      }

      // overrides for equals and getHashCode
   }

and

   public class DomainUserRole
   {
      public virtual DomainUser DomainUser { get; set; }
      public virtual string DataSegment { get; set; }  // Some group of data a user has access to, like US or China
      public virtual string RoleName { get; set; }
      public virtual string RoleDescription { get; set; }

      // extra field removed for breviety

      // overrides for equals and getHashCode
   }

My db schema is pretty simple.

alt text http://lh6.ggpht.com/_MV6QGBD11JE/S3iX2qcP_jI/AAAAAAAAEE0/PGIO07BlCSo/s800/Untitled.gif.jpg

I’ve got the IAutoMappingOverride classes started like this. But, I’m at a loss of how to setup the hasMany for roles. It keeps giving me

NHibernate.FKUnmatchingColumnsException: 
   Foreign key (FK20531BE4163641BB:tblDomainUserRoles [DomainUser])) 
   must have same number of columns as the referenced primary key 
   (tblDomainUsers [Domain_Id, DomainUserLogin]). 

How do I setup that foreign key to use both those fields?

   public class DomainUserMap : IAutoMappingOverride<DomainUser>
   {
      public void Override(AutoMapping<DomainUser> mapping)
      {
         mapping.CompositeId()
            .KeyProperty(user => user.Domain_Id, "Domain_Id")
            .KeyProperty(user => user.DomainUserLogin, "DomainUserLogin");

         // I"ve tried this.
         // mapping.HasMany(x => x.Roles)
         //   .KeyColumns.Add("Domain_Id")
         //   .KeyColumns.Add("DomainUserLogin");

         //  also tried this where I define this FK in DB with both fields.
         // mapping.HasMany(x => x.Roles)
         //   .ForeignKeyConstraintName("FK_tblDomainUserRoles_tblDomainUsers")

      }
   }

    public class DomainUserRoleMap : IAutoMappingOverride<DomainUserRole>
       {
          public void Override(AutoMapping<DomainUserRole> mapping)
          {
             mapping.CompositeId()
                .KeyReference(role => role.DomainUser)
                .KeyProperty(role => role.DataSegment)
                .KeyProperty(role => role.RoleName);         
          }
       }
  • 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-13T18:30:39+00:00Added an answer on May 13, 2026 at 6:30 pm

    I did endup hand editing the hbm files. It looks like the most recent build on fluent Nhibernate addresses this issue. Here is what my hbm file look like.

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
      <class xmlns="urn:nhibernate-mapping-2.2" name="AAA.Core.Entities.DomainUser, AAA.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`tblDomainUsers`">
        <composite-id mapped="false" unsaved-value="undefined">
          <key-property name="Domain_Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="Domain_Id" />
          </key-property>
          <key-property name="DomainUserLogin" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="DomainUserLogin" />
          </key-property>
        </composite-id>
        ... properties hidden for breviety
        <bag inverse="true" cascade="all-delete-orphan" lazy="false" name="Roles">
          <key>
            <column name="Domain_Id" />
            <column name="DomainUserLogin" />
          </key>
          <one-to-many class="AAA.Core.Entities.DomainUserRole, AAA.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
        </bag>
      </class>
    </hibernate-mapping>
    

    here is the file for roles.

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
      <class xmlns="urn:nhibernate-mapping-2.2" name="AAA.Core.Entities.DomainUserRole, AAA.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`tblDomainUserRoles`">
        <composite-id mapped="false" unsaved-value="undefined">
          <key-property name="DataSegment" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="DataSegment" />
          </key-property>
          <key-property name="RoleName" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <column name="RoleName" />
          </key-property>
          <key-many-to-one name="DomainUser" class="AAA.Core.Entities.DomainUser, AAA.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
            <column name="Domain_Id" />
            <column name="DomainUserLogin" />
          </key-many-to-one>
        </composite-id>
         ... properties hidden for breviety
      </class>
    </hibernate-mapping>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.