2011-01-08 39 views
6

gặp phải vấn đềNHibernate: Làm thế nào để giải quyết việc này "phương ngữ" cấu hình vấn đề

Khi chạy, tôi luôn nhận được NHibernate.MappingException sau:

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

Vâng, xây dựng hành động của nó được thiết lập để Embedded Resource. Các InnerException nói:

"Could not find the dialect in the configuration" 

Yêu cầu Thông tin

Dưới đây là tập tin cấu hình của tôi tên là 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> 

Mà thực sự là một copy-paste từ Configuration_Templates thư mục trong đó tôi chỉ thay đổi thông tin sau:

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" 

Và dưới đây là cách tôi đang sử dụng nó trong mã của tôi:

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

Thông tin bắt buộc

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

Môi trường

  1. Windows 7 Pro;
  2. Visual Studio 2010, nhắm mục tiêu .NET 4.0;
  3. NHibernate 3.0.0.GA;
  4. SQL Server 2005.

Câu hỏi

Tôi đã cố gắng để đưa tài sản phương ngữ trên dòng của cấu hình, và nó không phải làm việc.

Làm cách nào để giải quyết vấn đề về phương ngữ mà tôi có?

+1

Tải xuống mã nguồn NHibernate, đính kèm vào ứng dụng và cố gắng nắm bắt ngoại lệ khi được ném. –

+0

chưa làm việc với NH 3 - Tôi hơi ngạc nhiên khi đọc urn: nhibernate-configuration -___ 2.2 ____ trong tập tin cấu hình của bạn. – Marijn

+0

giải pháp nào về nó? – Kiquenet

Trả lời

9

Trông Allright với tôi ... bạn đã thấy những câu hỏi liên quan:

Những là những sai lầm dễ thực hiện có thể làm tăng ngoại lệ nhất định.

+0

+1 Tôi đã chắc chắn về các thông tin được đề cập ở trên, nhưng vẫn còn lỗi vẫn tồn tại. Tôi sẽ xem những gì tôi có thể làm với những gì Jani đề xuất trong bình luận của mình. Cảm ơn sự giúp đỡ của các bạn! =) –

+0

Xin chào Marijn! Tôi xin lỗi, tôi đã phải bỏ dự án này sang một bên trong một thời gian và tôi không thể mong đợi nó như bây giờ. Tôi sẽ chấp nhận hoặc cho bạn biết những gì không làm việc sau này khi tôi có thể quay trở lại dự án này mà từ đó câu hỏi này được đưa ra. Cảm ơn sự thông cảm và kiên nhẫn của bạn. =) –

3

Hai điều sẽ khắc phục vấn đề:

Không sử dụng này:

Configuration c = new Configuration(); 

Thay vào đó, sử dụng này:

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

Hãy chắc chắn rằng hoặc là bạn làm điều này trong chế độ ngủ đông của bạn. tệp cfg.xml:

<mapping assembly="Your assembly"/> 

HOẶC

AddAssembly(Assembly.GetCallingAssembly()); 

Làm cả hai sẽ tạo ra sự cố.

Các vấn đề liên quan