首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Nhibernate hbm到Fluent

从Nhibernate hbm到Fluent
EN

Stack Overflow用户
提问于 2014-06-17 18:17:43
回答 1查看 432关注 0票数 0

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

我在hbm中有以下内容

代码语言:javascript
复制
<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。

到目前为止,我有以下内容

代码语言:javascript
复制
 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");
        }
    }

但是我得到了以下错误

代码语言:javascript
复制
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进行配置时,我想我无法映射多对一。

有没有人能帮帮忙。

EN

回答 1

Stack Overflow用户

发布于 2014-06-17 23:06:49

您应该对列A使用KeyReference

代码语言:javascript
复制
.KeyReference(x => x.A, "A");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24261235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档