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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:43:11+00:00 2026-05-16T06:43:11+00:00

Ok I have 2 objects and a foreign key. The first object is. public

  • 0

Ok I have 2 objects and a foreign key.

The first object is.

    public class OutboundEmailMap : ClassMap<OutboundEmail>
{
    public OutboundEmailMap()
    {
        Table("OutboundEmail");

        Id(x => x.Id, "OutboundEmailId")
            .UnsavedValue(0)
            .GeneratedBy.Identity();

        Map(x => x.OutboundEmailGuid);
        Map(x => x.FromAccountName);
        Map(x => x.ToAccountName);
        Map(x => x.FromContactFirstName);
        Map(x => x.FromContactLastName);
        Map(x => x.ToContactFirstName);
        Map(x => x.ToContactLastName);
        Map(x => x.FromEmailAddress);
        Map(x => x.ToEmailAddress);
        Map(x => x.EmailTemplateID);
        Map(x => x.SentDate);
        Map(x => x.Subject);
        Map(x => x.XMLTokenDictionary);
        Map(x => x.IsFax);
        Map(x => x.TransmittalId);

        //References<Transmittal>(x => x.Transmittal)
        //    .Column("TransmittalID")
        //    .LazyLoad()
        //    .Cascade.None();

        HasOne<OutboundEmailStatus>(x => x.Status)
            .ForeignKey("FK_OutboundEmailStatus_OutboundEmail")
            .Cascade.None();
    }
}

The 2nd Class is

    public class OutboundEmailStatusMap : ClassMap<OutboundEmailStatus>
{
    public OutboundEmailStatusMap()
    {
        Table("OutboundEmailStatus");

        Id(x => x.Id, "OutboundEmailStatusID")
            .UnsavedValue(0)
            .GeneratedBy.Identity();

        References(x => x.OutboundEmail, "OutboundemailID");
        Map(x => x.EmailStatus, "EmailStatusID");
        Map(x => x.EmailStatusDate);
    }
}

And the Foreign Key is

USE [Mail]
GO

ALTER TABLE [dbo].[OutboundEmailStatus]  WITH CHECK ADD  CONSTRAINT   [FK_OutboundEmailStatus_OutboundEmail] FOREIGN KEY([OutboundEmailID])
REFERENCES [dbo].[OutboundEmail] ([OutboundEmailID])
GO

ALTER TABLE [dbo].[OutboundEmailStatus] CHECK CONSTRAINT [FK_OutboundEmailStatus_OutboundEmail]
GO

And Lastly this is the query that is generated

SELECT   top 20 this_.OutboundEmailId              as Outbound1_1_1_,
            this_.OutboundEmailGuid            as Outbound2_1_1_,
            this_.FromAccountName              as FromAcco3_1_1_,
            this_.ToAccountName                as ToAccoun4_1_1_,
            this_.FromContactFirstName         as FromCont5_1_1_,
            this_.FromContactLastName          as FromCont6_1_1_,
            this_.ToContactFirstName           as ToContac7_1_1_,
            this_.ToContactLastName            as ToContac8_1_1_,
            this_.FromEmailAddress             as FromEmai9_1_1_,
            this_.ToEmailAddress               as ToEmail10_1_1_,
            this_.EmailTemplateID              as EmailTe11_1_1_,
            this_.SentDate                     as SentDate1_1_,
            this_.Subject                      as Subject1_1_,
            this_.XMLTokenDictionary           as XMLToke14_1_1_,
            this_.IsFax                        as IsFax1_1_,
            this_.TransmittalId                as Transmi16_1_1_,
            outboundem2_.OutboundEmailStatusID as Outbound1_7_0_,
            outboundem2_.EmailStatusID         as EmailSta2_7_0_,
            outboundem2_.EmailStatusDate       as EmailSta3_7_0_,
            outboundem2_.OutboundemailID       as Outbound4_7_0_
FROM     OutboundEmail this_
     left outer join OutboundEmailStatus outboundem2_
       on this_.OutboundEmailId = outboundem2_.OutboundEmailStatusID
WHERE    this_.TransmittalId = '7789322e-acd6-4cb8-9c43-5bdaec52aa8a' /* @p0 */
ORDER BY this_.ToAccountName asc

So the issue is as you see, for whatever reason the query it generates tries to use the foreign key, though connecting the foreign key to OutboundEmailStatusID instead of OutboundEmailID

If anyone knows why this might happen, or an alternative approach, please let me know.

It seems really silly to me that this even happens?!

  • 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-16T06:43:11+00:00Added an answer on May 16, 2026 at 6:43 am

    A one-to-one in NHibernate is, by design, a relationship that joins over the primary key. It’s an implicit relationship, rather than explicit, in that the two entities are related only through an implied convention that if the two keys have the same value they’re associated. See: NHibernate one-to-one.

    Judging by your database design, you actually have a one-to-many – many-to-one relationship structure going on, not a one-to-one. Your domain model may express it as a one-to-one, but underlying it’s still a one-to-many; in the database your OutboundEmail can have many OutboundEmailStatus’s because there’s nothing stopping multiple rows having the same foreign-key value.

    Personally, I’d flip it around and put the foreign-key on the OuboundEmail. That way your OutboundEmail would have a many-to-one to OutboundEmailStatus. aka. an email has a single status, but a status could be associated with multiple emails.

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

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • 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 Simple: Check IBrowserManager May 16, 2026 at 9:53 am
  • Editorial Team
    Editorial Team added an answer Secondly i just create the process i don't know how… May 16, 2026 at 9:53 am
  • Editorial Team
    Editorial Team added an answer They don't see them at the exact same time. The… May 16, 2026 at 9:53 am

Trending Tags

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

Top Members

Related Questions

Let's say I have a class Voucher: public class Voucher { public Guid Id
Is it possible to perform a global reversed-find on NHibernate-managed objects? Specifically, I have
I have a model with a custom property class RecipeIngredient(models.Model): recipe = models.ForeignKey(Recipe) ingredient
I have 3 django models (simplified for this example): class Fighter (models.Model): name =
I have a Tag object (id, name) and a Tagging object (id, tag_id, type).
I'm pretty much a newb with spring-hibernate and I have been trying to make
I have two tables in a legacy database... tblParentTable (int id, string specialIdentifier, ...)
i have a model using user as a forgignKey. and in the admin, i
Consider the following models: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128)
I think this is a moderately neophyte question. I've been using NHibernate/FluentNHibernate for about

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.