【问题标题】:Nhibernate hbm to Fluent将 hbm 休眠到 Fluent
【发布时间】:2014-06-17 10:17:43
【问题描述】:

我需要使用 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 进行配置时,我认为我无法进行多对一映射。

所以有人可以帮忙。

【问题讨论】:

  • BTW:... 您可以“ExportTo”您的 Fluent-Mappings 以输出所有 *.hbm.xml 文件,然后直接进行前后比较。这是提示代码: .Mappings(m => m.FluentMappings .AddFromAssemblyOf() .ExportTo(@"C:\My_Mappings\")

标签: nhibernate fluent-nhibernate hbmxml


【解决方案1】:

您应该使用 KeyReference 代替 A 列。

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

【讨论】:

    猜你喜欢
    • 2011-04-28
    • 2016-12-11
    • 2013-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多