2011-01-08 8 views
6

problema encontradoNHibernate: ¿Cómo resolver este problema "dialecto" configuración

En tiempo de ejecución, siempre me dan el siguiente NHibernate.MappingException:

"Could not compile the mapping document: GI.InventoryManager.CYB.Mappings.Part.hbm.xml" 

Sí, su acción acumulación se establece en Embedded Resource. El InnerException dice:

"Could not find the dialect in the configuration" 

requerido Información

Aquí está mi archivo de configuración llamado hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > 
    <session-factory> 
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
    <property name="connection.connection_string"> 
     Server=(local);initial catalog=GI_IM_CYB;Integrated Security=SSPI 
    </property> 
    <property name="adonet.batch_size">10</property> 
    <property name="show_sql">false</property> 
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 
    <property name="use_outer_join">true</property> 
    <property name="command_timeout">60</property> 
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> 
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,  NHibernate.ByteCode.Castle</property> 
    </session-factory> 
</hibernate-configuration> 

que en realidad es un copiar y pegar de los Configuration_Templates carpeta en la que me solo cambió la siguiente información:

Session Factory: "Removed the NHibernate.Test namespace and let the property for itself" 
Dialect: "From MsSql2000Dialect To MsSql2005Dialect" 
Connection_String: "I changed the Initial Catalog attribute to input my own database name" 
Factory Class: "From LinFu to Castle" 

Y así es como lo estoy usando en mi código:

private void configBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { 
    Configuration c = new Configuration(); 
    c.AddAssembly(typeof(Part).Assembly); 
    lock (_sessionFactory) { 
     _sessionFactory = c.BuildSessionFactory(); 
    } 
} 

Información opcional

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="GI.InventoryManager.CYB" namespace="GI.InventoryManager.CYB.Types"> 
    <class name="Part" table="Parts" lazy="true"> 
    <id name="Id" column="part_id"> 
     <generator class="native"/> 
    </id> 
    <properties name="Description"/> 
    <properties name="Number"/> 
    <properties name="InStockQty"/> 
    <properties name="Cost"/> 
    </class> 
</hibernate-mapping> 


public class Part { 
    #region Private Members 

    private string _description; 
    private string _number; 

    #endregion 
    #region Constructors 

    /// <summary> 
    /// Initializes an instance of the GI.InventoryManager.CYB.Types.Part class. 
    /// </summary> 
    public Part() { } 

    #endregion 
    #region Properties 

    /// <summary> 
    /// Gets or sets the description of this part. 
    /// </summary> 
    public virtual string Description { 
     get { 
      return _description; 
     } set { 
      if (!string.IsNullOrWhiteSpace(value)) 
       _description = value.Trim(); 
     } 
    } 

    /// <summary> 
    /// Gets the underlying datastore unique identifier. 
    /// </summary> 
    public virtual int Id { get; private set; } 

    /// <summary> 
    /// Gets or sets the user-defined number. 
    /// </summary> 
    public virtual string Number { 
     get { 
      return _number; 
     } set { 
      if (!string.IsNullOrWhiteSpace(value)) 
       _number = value.Trim(); 
     } 
    } 

    /// <summary> 
    /// Gets or sets the in-stock quantity. 
    /// </summary> 
    public virtual int InStockQty { get; set; } 

    /// <summary> 
    /// Gets or sets the cost. 
    /// </summary> 
    public virtual double? Cost { get; set; } 

    /// <summary> 
    /// Gets the inventory value for this part. 
    /// </summary> 
    /// <remarks> 
    /// <para> 
    /// This read-only property returns the product of <see cref="T:InStockQty"/> and <see cref="Cost"/>. 
    /// In case the <b>Cost</b> property does not have a value, zero is returned. 
    /// </para> 
    /// </remarks> 
    public double InventoryValue { 
     get { 
      if (Cost.HasValue) 
       return InStockQty * Cost.Value; 
      return 0.0; 
     } 
    } 

    #endregion 
    #region Methods 



    #endregion 
} 

Medio Ambiente

  1. Windows 7 Pro;
  2. Visual Studio 2010, segmentación .NET 4.0;
  3. NHibernate 3.0.0.GA;
  4. SQL Server 2005.

Pregunta

ya he tratado de poner la propiedad dialecto en la línea de la configuración, y no trabajado.

¿Cómo resolver este problema dialectal que tengo?

+1

Descargue el código fuente de NHibernate, conéctelo a la aplicación y trate de detectar la excepción cuando se lance. –

+0

aún no he trabajado con NH 3 - Estoy un poco sorprendido de leer urn: nhibernate-configuration -___ 2.2 ____ en tu archivo de configuración. – Marijn

+0

alguna solución al respecto? – Kiquenet

Respuesta

9

Parece Allright a mí ... ¿has visto a estas preguntas relacionadas:

These son errores fáciles de hacer que pueden elevar la excepción dada.

+0

+1 Me he asegurado de la información mencionada anteriormente, pero el error persiste. Veré qué puedo hacer con lo que Jani propuso en su comentario. ¡Gracias por su gentil apoyo! =) –

+0

¡Hola Marijn! Lo siento, tuve que dejar de lado este proyecto por un tiempo y no puedo esperarlo desde ahora. Aceptaré o le diré lo que no funciona más adelante cuando pueda volver a este proyecto desde el que se emite esta pregunta. Gracias por su comprensión y paciencia. =) –

3

dos cosas va a solucionar el problema:

no utilice este:

Configuration c = new Configuration(); 

En su lugar, utilizar este:

Configuration c = new Configuration().Configure(); 

de asegurarse que lo hace en su hibernación. archivo cfg.xml:

<mapping assembly="Your assembly"/> 

O

AddAssembly(Assembly.GetCallingAssembly()); 

Hacer ambas cosas creará un problema.

Cuestiones relacionadas