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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:20:24+00:00 2026-05-11T10:20:24+00:00

Whenever I load a Task class, the Document property is always null, despite there

  • 0

Whenever I load a Task class, the Document property is always null, despite there being data in the db.

Task class:

public class Task {     public virtual Document Document { get; set; } 

Task Mapping override for AutoPersistenceModel:

public void Override(AutoMap<Task> mapping) {     mapping.HasOne(x => x.Document)         .WithForeignKey('Task_Id'); 

As you can see form what NHProf says is being run, the join condition is wrong, the WithForeignKey doesnt seem to take effect. In fact, i can write any string in the above code and it makes no difference.

FROM   [Task] this_     left outer join [Document] document2_     on this_.Id = document2_.Id 

It should be:

FROM   [Task] this_     left outer join [Document] document2_     on this_.Id = document2_.Task_Id 

If i hack the data in the db so that the ids match, then data is loaded, but obviously this is incorrect – but at least it proves it loads data.

Edit: rummaging in the fluent nhib source to find the XML produces this:

<one-to-one foreign-key='Task_Id' cascade='all' name='Document' class='MyProject.Document, MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' />  

Edit: heres the schema:

CREATE TABLE [dbo].[Document]( [Id] [int] IDENTITY(1,1) NOT NULL, [Task_Id] [int] NOT NULL,  CREATE TABLE [dbo].[Task]( [Id] [int] IDENTITY(1,1) NOT NULL, 

Anyone got any ideas?

Thanks

Andrew

  • 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. 2026-05-11T10:20:25+00:00Added an answer on May 11, 2026 at 10:20 am

    I think the problem here is that the ‘HasOne’ convention means that you are pointing at the other thing(the standard relational way to say ‘Many To One’/’One to One’); By putting a Task_ID on the document the actual relationship is a HasMany but you have some kind of implicit understanding that there will only be one document per task.

    Sorry – I don’t know how to fix this, but I will be interested in seeing what the solution is (I don’t use NHibernate or Fluent NHibernate, but I have been researching it to use in the future). A solution (from someone with very little idea) would be to make Documents a collection on Task, and then provide a Document property that returns the first one in the collection (using an interface that hides the Documents property so no one thinks they can add new items to it).

    Looking through documentation and considering eulerfx’s answer, Perhaps the approach would be something like:

    References(x => x.Document)     .TheColumnNameIs('ID')     .PropertyRef(d => d.Task_ID); 

    EDIT: Just so this answer has the appropriate solution: The correct path is to update the database schema to match the intent of the code. That means adding a DocumentID to the Task table, so there is a Many-To-One relationship between Task and Document. If schema changes were not possible, References() would be the appropriate resolution.

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

Sidebar

Ask A Question

Stats

  • Questions 192k
  • Answers 192k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The PageLoad event of your child page is called before… May 12, 2026 at 6:28 pm
  • Editorial Team
    Editorial Team added an answer Use setTimeout instead of setInterval. Something like: var checkTextValue =… May 12, 2026 at 6:28 pm
  • Editorial Team
    Editorial Team added an answer Use the cross product. That is, a vector perpendicular to… May 12, 2026 at 6:28 pm

Related Questions

Whenever I load a blog post onto the page with Ajax, I set the
I want some personally developed JavaScript code to execute whenever I load a page
I am using TinyMCE ( http://tinymce.moxiecode.com/ ) in a .NET page. Whenever I load
By default, phpMyAdmin shows me 30 rows whenever I load a table (the query

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.