【问题标题】:Fail to add new record on nHibernate many to one mapping无法在 nHibernate 多对一映射上添加新记录
【发布时间】:2011-05-17 08:08:48
【问题描述】:
String or binary data would be truncated.
The statement has been terminated.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.

Source Error: 
Line 33:             ITransaction tx = session.BeginTransaction();
Line 34:             session.SaveOrUpdate(productX);
Line 35:             tx.Commit();
Line 36:         }
Line 37: 

Source File: ProductService.cs    Line: 35 

Stack Trace: 
[SqlException (0x80131904): String or binary data would be truncated.
The statement has been terminated.]

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Aquamate.DataObjects.Core" assembly="Aquamate.DataObjects.Core">
    <class name="Product" table="revProduct">
        <id name="Pid" >
            <generator class="guid.comb" />
        </id>
        <many-to-one name="ProductCategory" class="Category" lazy="proxy">
            <column name="Catid" not-null="true" />
        </many-to-one>
        <property name="NameEng" not-null="true" />
        <property name="NameTch" not-null="true" />
        <property name="Status" not-null="true" />
        <property name="Sort" not-null="true" />
    </class>
</hibernate-mapping>

【问题讨论】:

    标签: nhibernate many-to-one


    【解决方案1】:

    此错误通常意味着您试图向数据库列插入一个值,其中数据的大小大于为该列定义的大小。

    检查数据库中定义的所有映射属性的大小,并将其与您尝试插入的数据进行比较。

    NHIbernate Profiler 可以成为你最好的朋友

    【讨论】:

      猜你喜欢
      • 2016-10-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多