title: NHibernate Error - "could not initialize a collection"
body: <p>I have many-to-one mappings working fine, but a one-to-many relationship between locations and location_times keeps giving me an error. </p>
  
  <p>I keep getting this error:
  <img src="https://i.stack.imgur.com/IHOaR.jpg" alt="enter image description here"></p>
  
  <p>on this line of code:
  <img src="https://i.stack.imgur.com/s3zMv.jpg" alt="enter image description here"></p>
  
  <p>Mappings look like this:</p>
  
  <p><strong>Location:</strong></p>
  
  <pre><code>public virtual IList&lt;LocationTimes&gt; LocationTimes { get; set; }
  
      public virtual int locationID { get; set; }
      public virtual IList&lt;LocationTimes&gt; LocationTimes { get; set; }
  
      public Location()
      {
          LocationTimes = new List&lt;LocationTimes&gt;();
      }
  </code></pre>
  
  <p><strong>Location Map:</strong></p>
  
  <pre><code> public class LocationMap : ClassMap&lt;Location&gt;
   {
      public LocationMap()
      {
          Table("Locations");
  
          Id(x =&gt; x.locationID).Column("ID");    
  
          HasMany(x =&gt; x.LocationTimes)
            .Inverse()
            .Cascade.All();   
  </code></pre>
  
  <p><strong>Location Table:</strong></p>
  
  <pre><code>CREATE TABLE [dbo].[Locations](
      [ID] [int] IDENTITY(1,1) NOT NULL
      ...
      CONSTRAINT [PK_Locations_1] PRIMARY KEY CLUSTERED 
      (
          [ID] ASC
      )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,     ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  </code></pre>
  
  <p><strong>LocationTimes:</strong></p>
  
  <pre><code>public class LocationTimes
  {
      public virtual int ID { get; set; }
      public virtual Location Location { get; set; }   
  }
  </code></pre>
  
  <p><strong>LocationTimesMap:</strong></p>
  
  <pre><code>public class LocationTimesMap : ClassMap&lt;LocationTimes&gt;
  {
      public LocationTimesMap()
      {
          Table("Location_Times");
  
          Id(x =&gt; x.ID);
          References(x =&gt; x.Location).Column("LID"); 
      }
  }
  </code></pre>
  
  <p><strong>Location_times table:</strong></p>
  
  <pre><code>CREATE TABLE [dbo].[Location_Times](
  [ID] [int] IDENTITY(1,1) NOT NULL,
  [LID] [int] NULL,
      [EHStart] [int] NULL,
  [EHEnd] [int] NULL,
      [EHSell] [money] NULL,
      CONSTRAINT [PK_Location_Times_1] PRIMARY KEY CLUSTERED 
      (
      [ID] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  </code></pre>
  
  <p><strong>The full error message:</strong></p>
  
  <blockquote>
    <p>"{"could not initialize a collection: [WhygoDomain.Location.LocationTimes#4]
    [SQL: SELECT locationti0_.Location_id as Location4_1_, locationti0_.ID as ID1_, locationti0_.ID as ID1_0_, locationti0_.LID as LID1_0_, locationti0_.EHStart as EHStart1_0_ 
    FROM Location_Times locationti0_ 
    WHERE locationti0_.Location_id=?]"}"</p>
  </blockquote>
  
  <p>I can see from the sql in the error message that it is indeed looking for locationti0_.Location_id, which I know doesn't exist. I don't know why it's looking for that though.</p>