1

我有一个 asp.net 应用程序,并添加了一个包含我的域对象和 xml 文件的库。

痕迹是:

Message=Could not determine type for: VaLibrary.Core.Domain.VAEmpresa, VaLibrary,    Version=1.0.5.18335, Culture=neutral, PublicKeyToken=null, for columns:    NHibernate.Mapping.Column(IdDev)

来源=NHibernate

我在网络上搜索同样的错误,但是,解决方案是针对其他映射选项(流利、城堡等)而不是针对 xml

我的代码课在这里

using System;
   using System.Text;
   using System.Collections.Generic;
   namespace VaLibrary.Core.Domain {

    public class VAEmpresa {
        private int? _id;
        private string _nombre;
        private string _tipo;
        public VAEmpresa() {
            VAJu_Dev = new List<VAJu>();
            VAJu_Pub = new List<VAJu>();
        }
        public virtual int Id {
            get {
                return (int)this._id;
            }
            set {
                this._id = value;
            }
        }
        public virtual string Nombre {
            get {
                return this._nombre;
            }
            set {
                this._nombre = value;
            }
        }
        public virtual string Tipo {
            get {
                return this._tipo;
            }
            set {
                this._tipo = value;
            }
        }
        public virtual IList<VAJu> VAJu_Dev { get; set; }
        public virtual IList<VAJu> VAJu_Pub { get; set; }
    }
}

参考是:

using System;
using System.Text;
using System.Collections.Generic;
namespace VaLibrary.Core.Domain {

    public class VAJu {
        private int? _id;
        private VAEmpresa _idDev;
        private VAEmpresa _idPub;
        private VACon _vACon;
        private string _titulo;
        private int _numerop;
        public VAJu() {
            VApllist = new List<VApllist>();
        }
        public virtual int Id {
            get {
                return (int)this._id;
            }
            set {
                this._id = value;
            }
        }
        public virtual VAEmpresa IdDev {
            get {
                return this._idDev;
            }
            set {
                this._idDev = value;
            }
        }
        public virtual VAEmpresa IdPub {
            get {
                return this._idPub;
            }
            set {
                this._idPub = value;
            }
        }
        public virtual VACon VACon {
            get {
                return this._vACon;
            }
            set {
                this._vACon = value;
            }
        }
        public virtual string Titulo {
            get {
                return this._titulo;
            }
            set {
                this._titulo = value;
            }
        }
        public virtual int Numerop {
            get {
                return this._numerop;
            }
            set {
                this._numerop = value;
            }
        }
        public virtual IList<VApllist> VApllist { get; set; }
    }
}

映射文件是:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="VaLibrary" namespace="VaLibrary.Core.Domain" xmlns="urn:nhibernate-mapping-2.2">
  <class name="VAEmpresa" table="VA-Empresa" lazy="true" >
    <id name="Id" column="Id">
      <generator class="identity" />
    </id>
    <property name="Nombre">
      <column name="nombre" sql-type="varchar" not-null="true" />
    </property>
    <property name="Tipo">
      <column name="tipo" sql-type="varchar" not-null="false" />
    </property>
    <bag name="VAJu_Dev" inverse="true" cascade="none">
      <key column="IdDev" />
      <one-to-many class="VaLibrary.Core.Domain.VAJu, VaLibrary" />
    </bag>
    <bag name="VAJu_Pub" inverse="true" cascade="none">
      <key column="IdPub" />
      <one-to-many class="VaLibrary.Core.Domain.VAJu, VaLibrary" />
    </bag>
  </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="VaLibrary" namespace="VaLibrary.Core.Domain" xmlns="urn:nhibernate-mapping-2.2">
  <class name="VAJu" table="VA-Ju" lazy="true" >
    <id name="Id" column="Id">
      <generator class="identity" />
    </id>
    <property name="Titulo">
      <column name="Titulo" sql-type="varchar" not-null="true" />
    </property>
    <many-to-one insert="false" update="false" lazy="false" name="IdDev">
      <column name="IdDev" sql-type="int" not-null="true" />
    </many-to-one>
    <property name="IdDev">
      <column name="IdDev" sql-type="int" not-null="true" />
    </property>
    <many-to-one insert="false" update="false" lazy="false" name="IdPub">
      <column name="IdPub" sql-type="int" not-null="true" />
    </many-to-one>
    <property name="IdPub">
      <column name="IdPub" sql-type="int" not-null="true" />
    </property>  
    <property name="Numerop">
      <column name="numero-p" sql-type="int" not-null="true" />
    </property>
    <bag name="VApllist" inverse="true" cascade="none">
      <key column="IdJu" />
      <one-to-many class="VApllist" />
    </bag>
  </class>
</hibernate-mapping>

DB 中的关系是:Va-Ju.IdDev FK 到 VA-Empresa.Id PK Va-JU.IdPub FK 到 VA-Empresa.Id PK

我试图改变,但都是一样的。

我可以?

非常感谢您的回答

[编辑]

我使用休眠 3.2

4

2 回答 2

1

映射缺少正确的关系 (对象到对象)映射。如何解释这一点的最佳方法是示例:

改变这个:

private VAEmpresa _idDev;

public virtual VAEmpresa IdDev 
{
  get { return this._idDev; }
  set { this._idDev = value; }
}

进入这个:

private VAEmpresa _dev;

public virtual VAEmpresa Dev  // Reference Object
{
  get { return this._idDev; }
  set 
  { 
      this._idDev = value; 
      if(_idDev != null)      // assure that with reference change
      {                       // the referenceId is changed as well
          IdDev = _idDev.Id
      }
  }
}
public virtual int IdDev { get; set; } // Refernece Id

现在我们有两个Dev引用的表示(它是类型VAEmpresa并且具有 int id)。我们可以映射它的工作方式。所以

改变这个:

<many-to-one insert="false" update="false" lazy="false" name="IdDev">
  <column name="IdDev" sql-type="int" not-null="true" />
</many-to-one>
<property name="IdDev">
  <column name="IdDev" sql-type="int" not-null="true" />
</property>

进入那个:

<many-to-one name="Dev" class="VAEmpresa" column="IdDev"
         insert="false" update="false" lazy="false" />
<property name="IdDev" not-null="true" />

从那一刻起,NHibernate 将知道Dev在 DB 中的何处搜索属性。实例化的列IdDev和类是VAEmpresa

如果代码只需要referenceId IdDev ...我们也有它。

小注意:我的经验是使用不同的只读设置。可编辑的是引用,只读的是referencId。这会强制代码使用现有的 VAEmpresa 对象,而 IdDev 可以是任何整数。处理复杂,但后来带来成果

于 2013-07-04T03:37:43.047 回答
0

ID 可能需要类型。你有:

<id name="Id" column="Id">
  <generator class="identity" />
</id>

尝试按如下方式指定类型:

<id name="Id" >
  <column name="Id" sql-type="int" not-null="true" unique="true" />
  <generator class="identity" />
</id>

另一个问题是您忘记将列/域的名称放在 bag 属性中。您需要输入实际的列名而不是属性名。让我向您展示 VAJu:

 <bag name="VApllist" inverse="true" cascade="none">
  <key column="Id"  />
  <one-to-many class="VaLibrary.Core.Domain.VApllist" column="Id"  />
 </bag>
于 2013-07-03T17:45:02.583 回答