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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:20:14+00:00 2026-05-13T06:20:14+00:00

I have these related tables in my database: table [Files]: FileID FileName —— ——–

  • 0

I have these related tables in my database:

table [Files]:
FileID    FileName
------    --------
1         /data/foo.jpeg
2         /data/bar.gif

table [Attachments]:
FileID    DocumentID    Caption
------    ----------    -------
1         10            Foo is awesome.
1         20            Foo is horrible.
2         10            Bars are my favorite.

table [Documents]:
DocumentID    Title
----------    -----
10            Things Jack loves.
20            Stuff Mary hates.

This is how they are currently mapped in NHibernate:

<class name="File" table="Files">
    <id name="Id" type="System.Int32" column="FileID">
        <generator class="identity" />
    </id>
    <property name="FileName" column="FileName" type="System.String" />  
</class>

<joined-subclass name="Attachment" table="Attachments" extends="File">
    <key column="FileID" />
    <property name="DocumentID" column="DocumentID" type="System.Int32" />
    <property name="Caption" column="Caption" type="System.String" />
</joined-subclass>

<class name="Document" table="Documents">
    <id name="Id" type="System.Int32" column="DocumentID">
        <generator class="identity" />
    </id>
    <property name="Title" column="Title" type="System.String" />
</class>

I know that this mapping does not quite fit the schema for the Attachments table.
Is there a better way to map these tables?

(This is related to my previous question.)

  • 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-13T06:20:14+00:00Added an answer on May 13, 2026 at 6:20 am

    To elaborate on the above answer, you can use the many-to-one element to set up the relationship and use collection mapping to make the relationship bi-directional, which seems like it could be useful to your schema.

    You’d use the many-to-one element in the mapping for the attachments. For example,

    <many-to-one name="File" class="File" column="FileID"/>
    

    And you can specify the inverse on the mapping for files:

    <set name="Attachments" inverse="true" lazy="true">
        <key column="FileID" />
        <one-to-many class="Attachment" />
    </set>
    

    You can do the same thing for the documents. Names above are just taken from the schema, but you’d still need to make sure they match their classes and etc. But that’s the overall idea.

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

Sidebar

Related Questions

I have lots of tables with statistical data (environment related) and wondering if there
I have few tables in the database with parent table say P is having
I have a long running insert transaction that inserts data into several related tables.
Data is/are frequently transmitted as tables, for example in CSV files or HTML <table>
I have these two related tables Client (ClientId, Name) and ClientDescription (ClientDescriptionId, (FK) ClientId,
I have these data : 4 pippo pluto paperino 10 marco paolo roberto 2
I have a simple web application with database tables orders and products that I'm
Suppose I have a MySQL database named DB, and a table named ContactInfo. The
I have Table1 and Table2 related on Table1.ID. There can be zero or more
I have these models: class Model1(models.Model): ... class Model2(models.Model): m1 = models.OneToOneField(Model1, related_name='m2') ...

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.