本文介绍了NHibernate的:如何解决这个"方言"配置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到的问题

在运行时,我总是得到以下 NHibernate.MappingException

At runtime, I always get the following NHibernate.MappingException:

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

是的,它的生成操作设置为嵌入的资源。设置InnerException说:

Yes, its build action is set to Embedded Resource. The InnerException says:

"Could not find the dialect in the configuration"

必需的信息

下面是我命名的配置文件的hibernate.cfg.xml

Here is my configuration file named 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>

这实际上是一个复制粘贴的 Configuration_Templates 的文件夹中,我只改了以下信息:

Which actually is a copy-paste from the Configuration_Templates folder in which I only changed the following information:

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"

和这里是我如何使用它在我的code:

And here's how I'm using it in my code:

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

可选信息

<?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
}

环保

  1. 的Windows 7专业版;
  2. 在Visual Studio 2010中,针对.NET 4.0;
  3. 在NHibernate的3.0.0.GA;
  4. 在SQL Server 2005中。

问题

我已经尝试把方言财产上的配置线,并没有奏效。

I have already tried to put the dialect property on the line of the configuration, and it neither worked.

如何解决这个问题的话,我有吗?

How to solve this dialect problem that I have?

推荐答案

看起来还好吧,我...你见过这些相关的问题:

Looks allright to me ... have you seen these related questions:

  • nhibernate-could-not-find-oracle-dialect-in-configuration解决方案:调用 configuration.Configure()添加映射文件之前

  • nhibernate-could-not-find-oracle-dialect-in-configuration solution: call configuration.Configure() before adding the mapping document

nhibernate-and-sqlite-could-not-compile-the-mapping-document解决方案:将的hibernate.cfg.xml 来输出目录

nhibernate-and-sqlite-could-not-compile-the-mapping-document solution: copy the hibernate.cfg.xml to the outputdirectory

这些容易出错,使能提高给定异常。

These are easy mistakes to make that can raise the given exception.

这篇关于NHibernate的:如何解决这个&QUOT;方言&QUOT;配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 15:48