title: Fluent NHibernate/SQL Server 2008 insert query problem
body: <p>I'm new to Fluent NHibernate and I'm running into a problem.</p>
  
  <p>I have a mapping defined as follows:</p>
  
  <pre><code>public PersonMapping()
      {
          Id(p =&gt; p.Id).GeneratedBy.HiLo("1000");
          Map(p =&gt; p.FirstName).Not.Nullable().Length(50);
  
          Map(p =&gt; p.MiddleInitial).Nullable().Length(1);
  
          Map(p =&gt; p.LastName).Not.Nullable().Length(50);
          Map(p =&gt; p.Suffix).Nullable().Length(3);
          Map(p =&gt; p.SSN).Nullable().Length(11);
          Map(p =&gt; p.BirthDate).Nullable();
          Map(p =&gt; p.CellPhone).Nullable().Length(12);
          Map(p =&gt; p.HomePhone).Nullable().Length(12);
          Map(p =&gt; p.WorkPhone).Nullable().Length(12);
          Map(p =&gt; p.OtherPhone).Nullable().Length(12);
          Map(p =&gt; p.EmailAddress).Nullable().Length(50);
          Map(p =&gt; p.DriversLicenseNumber).Nullable().Length(50);
  
          Component&lt;Address&gt;(p =&gt; p.CurrentAddress, m =&gt;
          {
              m.Map(p =&gt; p.Line1, "Line1").Length(50);
              m.Map(p =&gt; p.Line2, "Line2").Length(50);
              m.Map(p =&gt; p.City, "City").Length(50);
              m.Map(p =&gt; p.State, "State").Length(50);
              m.Map(p =&gt; p.Zip, "Zip").Length(2);
          });
  
          Map(p =&gt; p.EyeColor).Nullable().Length(3);
          Map(p =&gt; p.HairColor).Nullable().Length(3);
          Map(p =&gt; p.Gender).Nullable().Length(1);
          Map(p =&gt; p.Height).Nullable();
          Map(p =&gt; p.Weight).Nullable();
          Map(p =&gt; p.Race).Nullable().Length(1);
          Map(p =&gt; p.SkinTone).Nullable().Length(3);
          HasMany(p =&gt; p.PriorAddresses).Cascade.All();
      }
  
  
      public PreviousAddressMapping()
      {
          Table("PriorAddress");
  
          Id(p =&gt; p.Id).GeneratedBy.HiLo("1000");
          Map(p =&gt; p.EndEffectiveDate).Not.Nullable();
          Component&lt;Address&gt;(p =&gt; p.Address, m =&gt;
          {
              m.Map(p =&gt; p.Line1, "Line1").Length(50);
              m.Map(p =&gt; p.Line2, "Line2").Length(50);
              m.Map(p =&gt; p.City, "City").Length(50);
              m.Map(p =&gt; p.State, "State").Length(50);
              m.Map(p =&gt; p.Zip, "Zip").Length(2);
          });
  
      }
  </code></pre>
  
  <p>My test is </p>
  
  <pre><code>    [Test]
      public void can_correctly_map_Person_with_Addresses()
      {
          var myPerson = new Person("Jane", "", "Doe");
          var priorAddresses = new[]
          {   
              new PreviousAddress(ObjectMother.GetAddress1(), DateTime.Parse("05/13/2010")),
              new PreviousAddress(ObjectMother.GetAddress2(), DateTime.Parse("05/20/2010"))
          };
  
          new PersistenceSpecification&lt;Person&gt;(Session)
              .CheckProperty(c =&gt; c.FirstName, myPerson.FirstName)
              .CheckProperty(c =&gt; c.LastName, myPerson.LastName)
              .CheckProperty(c =&gt; c.MiddleInitial, myPerson.MiddleInitial)
              .CheckList(c =&gt; c.PriorAddresses, priorAddresses)
  
              .VerifyTheMappings();
      }
  </code></pre>
  
  <p>GetAddress1() (yeah, horrible name) has Line2 == null</p>
  
  <p>The tables seem to be created correctly in sql server 2008, but the test fails with a SQLException  "String or binary data would be truncated."  When I grab the sql statement in SQL Profiler, I get</p>
  
  <pre><code>exec sp_executesql N'INSERT INTO PriorAddress (Line1, Line2, City, State, Zip, 
  EndEffectiveDate, Id) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6)',N'@p0 
  nvarchar(18),@p1 nvarchar(4000),@p2 nvarchar(10),@p3 nvarchar(2),@p4 nvarchar(5),@p5 
  datetime,@p6 int',@p0=N'6789 Somewhere Rd.',@p1=NULL,@p2=N'Hot 
  Coffee',@p3=N'MS',@p4=N'09876',@p5='2010-05-13 00:00:00',@p6=1001
  </code></pre>
  
  <p>Notice the @p1 parameter is being set to nvarchar(4000) and being passed a NULL value.  </p>
  
  <p>Why is it setting the parameter to nvarchar(4000)?  How can I fix it?</p>
  
  <p>Thanks!</p>
  
  <p>My first theory that it was related to the Line2 parameter was wrong.  I added a value to Line2, re-ran the test, and I'm still getting the same error.</p>
  
  <pre><code>exec sp_executesql N'INSERT INTO PriorAddress 
         (Line1, Line2, City, State, Zip, EndEffectiveDate, Id) 
  VALUES (@p0,   @p1,   @p2,   @p3,  @p4, @p5,              @p6)',
  N'@p0 nvarchar(18),@p1 nvarchar(6),@p2 nvarchar(10),@p3 nvarchar(2),@p4 
  nvarchar(5),@p5 datetime,@p6 int',
  @p0=N'6789 Somewhere Rd.',
  @p1=N'A test',
  @p2=N'Hot Coffee',
  @p3=N'MS',
  @p4=N'09876',
  @p5='2010-05-13 00:00:00',
  @p6=1001
  </code></pre>