title: fluent nhibernate hasmany relationship could not insert
body: <p>I have the following tables:</p>
  
  <ul>
  <li>LANDLORD = Id (Primary Key), FirstName, Surname, EmailAddress, Title;</li>
  <li>PROPERTY = Id (Primary Key), Type, NumberOfBedrooms, Address1, Address2, City, County, PostCode, LandlordId (Foreign Key to Landlord entity);</li>
  </ul>
  
  <p>My Domain classes are:</p>
  
  <pre><code>public class Landlord:BaseEntity
  {
      public virtual string Title { get; set; }
      public virtual string Surname { get; set; }
      public virtual string FirstName { get; set; }
      public virtual string EmailAddress { get; set; }
      public virtual IList&lt;Property&gt; Properties { get; set; }
  
      public Landlord()
      {
          Properties = new List&lt;Property&gt;();
      }
  }
  
  public class Property:BaseEntity
  {
      public virtual string Type { get; set; }
      public virtual int NumberOfBedrooms { get; set;}
      public virtual string Address1 { get; set; }
      public virtual string Address2 { get; set; }
      public virtual string City { get; set; }
      public virtual string County { get; set; }
      public virtual string PostCode { get; set; }
      public virtual Landlord Landlord { get; set; }
  
  }
  </code></pre>
  
  <p>My Fluent NHibernate maps are:</p>
  
  <pre><code>public sealed class LandlordMap:ClassMap&lt;Landlord&gt;
  {
      public LandlordMap()
      {
          Id(x =&gt; x.Id).GeneratedBy.Identity();
          Map(x =&gt; x.Title);
          Map(x =&gt; x.Surname);
          Map(x =&gt; x.FirstName);
          Map(x =&gt; x.EmailAddress);
          HasMany(x =&gt; x.Properties)
              .KeyColumns.Add("LandlordId")
              .Inverse()
              .Cascade.All();
          Table("LANDLORD");
      }
  }
  
  public sealed class PropertyMap:ClassMap&lt;Property&gt;
  {
      public PropertyMap()
      {
          Id(x =&gt; x.Id).GeneratedBy.Identity(); 
          Map(x =&gt; x.Type);
          Map(x =&gt; x.NumberOfBedrooms);
          Map(x =&gt; x.Address1);
          Map(x =&gt; x.Address2);
          Map(x =&gt; x.City);
          Map(x =&gt; x.County);
          Map(x =&gt; x.PostCode);
          References(x =&gt; x.Landlord, "LandlordId");
          Table("PROPERTY");
      }
  }
  </code></pre>
  
  <p>To test that a Landlord is saved to the database, I have the following code:</p>
  
  <pre><code>public class Program
  {
      static void Main(string[] args)
      {
          ILandlordRepository rep = new LandlordRepository();
  
          //Create property object
          Property p1 = new Property
          {
              Address1 = "123 LA Road",
              Address2 = "Bilston",
              City = "Harlem",
              County = "West Mids",
              NumberOfBedrooms = 2,
              PostCode = "wv134wd",
              Type = "Bungalow"
          };
  
          //Create landlord and assign property
          var landlord = new Landlord();
          landlord.Title = "Dr";
          landlord.FirstName = "Rohit";
          landlord.Surname = "Kumar";
          landlord.EmailAddress = "rkhkp@p.com";
          landlord.Properties.Add(p1);
  
          //Add to the database
          rep.SaveOrUpdate(landlord);
  
  
          Console.ReadKey();
  
      }
  }
  </code></pre>
  
  <p>When I call SaveOrUpdate I get this error:</p>
  
  <blockquote>
    <p>could not insert: [Homes4U.Service.DomainClasses.Property][SQL: INSERT INTO PROPERTY (Type, NumberOfBedrooms, Address1, Address2, City, County, PostCode, LandlordId) VALUES (?, ?, ?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()]</p>
  </blockquote>
  
  <p>Does anybody now why this is happening?</p>