0

I have a requirement to write the mapping using Nhibernate fluent.

I have the following in hbm

<class name="XYZ" table="Some_Table">
    <composite-id>
      <key-many-to-one name="A" column="A_ID"/>
      <key-property name="Term" type="Some_Assembly">
        <column name="YEAR"/>
        <column name="MONTH"/>
      </key-property>
    </composite-id>
    <property name="P" column="P"/>
  </class>

and I would need to rewrite this in fluent. the main reason is that we are moving away from hbm files to fluent.

so far I have the following

 public class XYZMap: ClassMap<XYZ>
    {
        public XYZMap()
        {
            Table("Some_Table");

            CompositeId()
                .KeyProperty(x=> x.Term, set =>
                {
                    set.ColumnName("Year");
                    set.ColumnName("Month");
                    set.Type(typeof(Some_Assembly));
                })
                .KeyProperty(x=> x.A, set =>
                {
                    set.ColumnName("A");
                    set.Type(typeof (Other_Assembly));
                });



            Map(x=> x.P, "P");
        }
    }

But I am getting the following error

X.Y.TestZ.PostCreate:
SetUp : Autofac.Core.DependencyResolutionException : An exception was thrown while executing a resolve operation. See the InnerException for details.
  ----> FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.


  ----> NHibernate.MappingException : Could not compile the mapping document: (XmlDocument)
  ----> NHibernate.MappingException : Could not determine type for: Other_Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(A_ID)

I think I am unable to map many-to-one when I am trying to configure using fluent.

So can someone please help.

Robert Dinaro
  • 508
  • 3
  • 8
  • 23
  • BTW:... You can "ExportTo" your Fluent-Mappings to output all of the *.hbm.xml files , and then do a direct before and after comparison. Here is the hint code : .Mappings(m => m.FluentMappings .AddFromAssemblyOf() .ExportTo(@"C:\My_Mappings\") – granadaCoder Jun 17 '14 at 15:58

1 Answers1

1

You should be using KeyReference instead for column A.

.KeyReference(x => x.A, "A");
Cole W
  • 15,123
  • 6
  • 51
  • 85