Nhibernate hbm to Fluent

时间:2014-06-17 10:17:43

标签: nhibernate fluent-nhibernate hbmxml

我需要使用Nhibernate流利的写作映射。

我在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>

我需要用流利的语言重写一遍。主要原因是我们正在从hbm文件转向流畅。

到目前为止,我有以下

 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");
        }
    }

但是我收到以下错误

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)

我想当我尝试使用流畅的配置时,我无法映射多对一。

有人可以帮忙。

1 个答案:

答案 0 :(得分:1)

您应该使用KeyReference代替A列。

.KeyReference(x => x.A, "A");