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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:58:56+00:00 2026-05-12T09:58:56+00:00

I have a legacy table with composite keys that are mapped to 3 other

  • 0

I have a legacy table with composite keys that are mapped to 3 other tables, since this table have other attributes in it, since it is not a simple mapping table, I can’t use the many-to-many set solution to map this.

The following is what I have done:

<class name="classA" table="A">
<composite-id name="ID" class="AKey">
  <key-many-to-one name="Id_one" class="One" column="Id_one" />
  <key-many-to-one name="Id_two" class="Two" column="Id_two" />
  <key-many-to-one name="Id_three" class="Three" column="Id_three" />
</composite-id>

AKey is merely a struct that holds the three ids, and Id_one, Id_two, and Id_three are all defined as int in their respective class.

public struct Akey {
    public int Id_one { get; set; }
    public int Id_two { get; set; }
    public int Id_three { get; set; }
}

This compiles fine, but when I try to run it, it gives me an error message:

NHibernate.QueryException : Type mismatch in NHibernate.Criterion.SimpleExpression: ID expected type AKey, actual type System.Int32

Please advise on what I have done wrong or missed.

Thanks a bunch!

  • 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-12T09:58:56+00:00Added an answer on May 12, 2026 at 9:58 am

    If you are going to use key-many-to-one you would put the class:

    public class Akey {
        public virtual One One {get; set;}
        public virtual Two Two {get; set;}
        public virtual Three Three {get; set;}
    }
    

    Otherwise if you want the Id you just map them as properties of classA:

     <composite-id>
         <key-property name="Id_one" column="Id_one" />
         <key-property name="Id_two" column="Id_two" />
         <key-property name="Id_three" column="Id_three" />
     </composite-id>
    

    .

    public class classA {
        public virtual int Id_one {get; set;}
        public virtual int Id_two {get; set;}
        public virtual int Id_three {get; set;}
    
        // ... rest of props ...
    }
    

    Or as a composite like you have:

     <composite-id name="ID" class="AKey">
         <key-property name="Id_one" column="Id_one" />
         <key-property name="Id_two" column="Id_two" />
         <key-property name="Id_three" column="Id_three" />
     </composite-id>
    

    .

    public class AKey {
        public virtual int Id_one {get; set;}
        public virtual int Id_two {get; set;}
        public virtual int Id_three {get; set;}
    }
    
    public class classA {
        public virtual AKey ID {get; set;}
    
        // ... rest of props ...
    }
    

    Finally …

     <composite-id>
       <key-many-to-one name="Id_one" class="One" column="Id_one" />
       <key-many-to-one name="Id_two" class="Two" column="Id_two" />
       <key-many-to-one name="Id_three" class="Three" column="Id_three" />
     </composite-id>
    

    .

    public class classA {
        public virtual One One {get; set;}
        public virtual Two Two {get; set;}
        public virtual Three Three {get; set;}
    
        // ... rest of props ...
    }
    

    Going to punt on whether you can use a struct because I’m not competent on them in C#.

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

Sidebar

Related Questions

I have a legacy table that has as a part of its natural key
In a legacy database I have to work with nested tables that are associated
Im working on a legacy database, that cant be changed. I have a table
I have some legacy layouts with nested tables. I'd like the parent table's <td>
I have two tables in a legacy database that I need to map using
I have a legacy data table in SQL Server 2005 that has a PK
I have a legacy MS Access 2007 table that contains 52 fields (1 field
I have A Legacy system that runs on a SQL Server 2005. Current table
We have a legacy application running tomcat that publishes data in a simple html
I have 2 entities for legacy db with composite keys, one of them has

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.