title: NHibernate multi column ManyToOne mapping with Mapping By-Code
body: <p>I am trying to convert my FluentNHibernate mappings to NHibernate Mapping By-code using NHibernate 3.3.3. The goal is to upgrade to NHibernate 3.3.3 and to cut down on the number of assemblies being distributed.</p>
  
  <p>However when I compile and run I get the following exception:</p>
  
  <blockquote>
    <p>NHibernate.MappingException: Multi-columns property can't be mapped through single-column API.</p>
  </blockquote>
  
  <p>The XML mapping FluentNHibernate gets my looks like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;many-to-one cascade="none" class="TextDto" fetch="join" lazy="false" name="Name" not-found="ignore"&gt;
    &lt;column name="NameTextId" unique="false" /&gt;
    &lt;column name="LanguageId" unique="false" /&gt;
  &lt;/many-to-one&gt;
  </code></pre>
  
  <p>Here is my new By-Code mapping:</p>
  
  <pre class="lang-c-sharp prettyprint-override"><code>this.ManyToOne(u =&gt; u.Name, c =&gt;
  {
      c.Cascade(Cascade.None);
      c.Class(typeof(TextDto));
      c.Columns(
          x =&gt;
          {
              x.Name("NameTextId");
              x.Unique(false);
          },
          x =&gt;
          {
              x.Name("LanguageId");
              x.Unique(false);
          });
      c.Fetch(FetchKind.Join);
      c.Lazy(LazyRelation.NoLazy);
      c.NotFound(NotFoundMode.Ignore);
      c.Unique(false);
  });
  </code></pre>
  
  <p>This is the old FluentNHibernate mapping:</p>
  
  <pre class="lang-c-sharp prettyprint-override"><code>References(x =&gt; x.Name)
      .Columns("NameTextId", "LanguageId")
      .Cascade.None()
      .Fetch.Join()
      .NotFound.Ignore()
      .Not.Unique()
      .Not.LazyLoad();
  </code></pre>
  
  <p>For Completeness the property type involved:</p>
  
  <pre class="lang-c-sharp prettyprint-override"><code>public class TextDto
  {
      public TextCompositeId Id { get; set; }
      public string PluralText { get; set; }
      public string SingularText { get; set; }
      public override bool Equals(object obj)
      {
          var text = (TextDto)obj;
          if (text == null) return false;
          return this.Id.Equals(text.Id);
      }
      public override int GetHashCode()
      {
          return this.Id.GetHashCode();
      }
  }
  </code></pre>
  
  <p>And an example of the property in an entity:</p>
  
  <pre class="lang-c-sharp prettyprint-override"><code>public class CharacteristicValue
  {
      public CharacteristicValueCompositeId Id { get; set; }
      public TextDto Name { get; set; }
      public string LanguageIdentity { get; set; }
      public string Value
      {
          get
          {
              string value = null;
              if (this.ValueMultilingual != null) return this.ValueMultilingual.SingularText;
              else if (!string.IsNullOrEmpty(this.ValueMeta)) return this.ValueMeta;
              return value;
          }
      }
      public TextDto ValueMultilingual { get; set; }
      public string ValueMeta { get; set; }
      public override bool Equals(object obj)
      {
          if (obj == null) return false;
          if (object.ReferenceEquals(this, obj)) return true;
          CharacteristicValue characteristicValue = obj as CharacteristicValue;
          if (characteristicValue == null) return false;
          if (this.Id != characteristicValue.Id) return false;
          return true;
      }
      public override int GetHashCode()
      {
          return this.Id.GetHashCode();
      }
  }
  </code></pre>
  
  <p>So, how do I get the xml-mapping I used to get with FluentNHibernate but with NHiberbate's Mapping By-Code?</p>