0

我需要使用 Nhibernate fluent 编写映射。

我在 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 文件转向 fluent。

到目前为止,我有以下

 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)

我想当我尝试使用 fluent 进行配置时,我无法映射多对一。

所以有人可以帮忙。

4

1 回答 1

1

您应该KeyReference改用 A 列。

.KeyReference(x => x.A, "A");
于 2014-06-17T15:06:49.090 回答