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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:04:37+00:00 2026-05-18T01:04:37+00:00

I have the following classes public class Contact { public Contact() { Addresses =

  • 0

I have the following classes

public class Contact
{
    public Contact() {
        Addresses = new List<Address>();
        EmailAddresses = new List<EmailAddress>();
        PhoneNumbers = new List<PhoneNumber>();
    }
    public virtual int ContactID { get; private set; }
    public virtual Firm Firm { get; set; }
    public virtual ContactType ContactType { get; set; }
    public virtual string FullName { get; set; }
    public virtual string FiscalCode { get; set; }
    public virtual string Notes { get; set; }
    public virtual ContactRole ContactRole { get; set; }

    public virtual IList<Address> Addresses { get; private set; }
    public virtual IList<EmailAddress> EmailAddresses { get; private set; }
    public virtual IList<PhoneNumber> PhoneNumbers { get; private set; }
}

public class Address
{
    public virtual int AddressID { get; private set; }
    public virtual string StreetAddress { get; set; }
    public virtual string ZipCode { get; set; }
    public virtual string City { get; set; }
    public virtual Province Province { get; set; }
    public virtual Country Country { get; set; }
    public virtual Contact Contact { get; set; }
    public virtual AddressType AddressType { get; set; }
    public virtual bool PostalAddress { get; set; }
}

These classes have been mapped to the database using FluentNHibernate. These are the mapping classes

public ContactMap() {
    Table( "Contacts" );
    Id( c => c.ContactID ).Column( "ContactID" ).GeneratedBy.Identity();
    References( c => c.Firm ).Column( "FirmID" );
    References( c => c.ContactType ).Column( "ContactTypeID" );
    Map( c => c.FullName );
    Map( c => c.FiscalCode );
    Map( c => c.Notes );
    References( c => c.ContactRole ).Column( "ContactRoleID" );
    HasMany( c => c.Addresses ).Cascade.SaveUpdate();
    HasMany( c => c.EmailAddresses ).Cascade.SaveUpdate();
    HasMany( c => c.PhoneNumbers ).Cascade.SaveUpdate();
}


public AddressMap() {
    Table( "Addresses" );
    Id( a => a.AddressID ).Column( "AddressID" ).GeneratedBy.Identity();
    Map( a => a.StreetAddress );
    Map( a => a.ZipCode );
    Map( a => a.City );
    References( a => a.Province ).Column( "ProvinceID" );
    References( a => a.Country ).Column( "CountryID" );
    References( a => a.Contact ).Column( "ContactID" );
    References( a => a.AddressType ).Column( "AddressTypeID" );
    Map( a => a.PostalAddress );
}

I am trying to load a considerable amount of contacts inside the database using these classes. My code that create these object can be logically explained as follow

Create a contact
For each address of this contact 
    create an address
    set the contact address
    add the address to the contact collection
Next
For each email of this contact 
    create an email
    set the contact email
    add the email to the contact collection
Next

I have no problem with all the descendant collection like Email, PhoneNumber except that I have a problem with Address. In fact when I try to insert an contact that has at least one address I get the following error

Could not insert collection: [GSLConverter.Entities.Contact.Addresses#3551][SQL: UPDATE Addresses SET AuthorID = @p0 WHERE AddressID = @p1]
Invalid column name 'AuthorID'

Instead of using ContactID is using AuthorID. Where does that AuthorID come from????

These are the queries that NHibernate execute on the server

INSERT INTO Addresses (StreetAddress, ZipCode, City, PostalAddress, ProvinceID, CountryID, ContactID, AddressTypeID) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7); 
select SCOPE_IDENTITY();
@p0 = 'xxx xxxxxx, 69 ', @p1 = '80142', @p2 = 'xxxxxx', @p3 = False, @p4 = 1, @p5 = 113, @p6 = 3632, @p7 = 1

UPDATE Addresses SET AuthorID = @p0 WHERE AddressID = @p1;
@p0 = 3632, @p1 = 26

@Stefan Steinegger: this is the mapping of the class, the only one, that reference an AuthorID member

public IssueNoteMap() {
    Table( "IssueNotes" );
    Id( ino => ino.IssueNoteID ).Column( "IssueNoteID" ).GeneratedBy.Identity();
    References( ino => ino.Issue ).Column( "IssueID" );
    Map( ino => ino.NoteDate );
    Map( ino => ino.NoteTitle );
    Map( ino => ino.NoteBody );
    References( ino => ino.Author ).Column( "AuthorID" );
}

The AuthorID field is a reference to the Contact table that have not be still mapped on the Contact side (as you can see from the previous Contact mapping

  • 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-18T01:04:38+00:00Added an answer on May 18, 2026 at 1:04 am

    Is IssueNote.Author by any chance a type of Contact? If so, the Fluent Mapping of

    References( ino => ino.Author ).Column( "AuthorID" );
    

    is attempting to update your ‘Addresses’ table to ensure that it also has the ContactIdstored in the Foreign Key of AuthorId which you have told it that IssueNote.Author uses when mapping to Contacts

    You have told nHibernate this:

    alt text

    When you really want this:
    alt text

    So, change the IssueNoteMap to the following so that the ContactId is used to map the Author and it should work

    References( ino => ino.Author ).Column( "ContactId" );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two classes: public class Address { public string AddressLine1 {
I have the following classes [XmlRoot] public class AList { public List<B> ListOfBs {get;
I have the following existing classes: class Gaussian { public: virtual Vector get_mean() =
I have the following classes: public class MyItems : List<MyItem> { ... } public
I have two following classes: public class User { public virtual Guid Id {
I have the following classes: public class DrawableComplexEntity2D { public List<GameComponent> Components { get;
I have the following classes public class Person { public virtual int Id {
I have the following classes public class Person { public virtual int Id {
I have the following classes: public class DictionaryBuilder<T> where T : IDictionary<string, object>, new()
If I have the following classes: public class MyItems : List<MyItem> { .. }

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.