2013-01-18 118 views
2

我有一个sql类中的表,其中有一列是一个ID,另一个是fImage。 fImage列的数据类型是Image。我使用nhibernate加载所有图像,并希望将其绑定到图片框控件中。但是,当使用nhibernate读取数据时,我们正在发生异常nhibernate无法反序列化可序列化的属性Nhibernate无法反序列化一个可序列化的属性

我经历了一些链接在stackoverflow和谷歌,但似乎没有为我工作。

这里我给出了示例hbm文件和类文件。

namespace BlackOpsP2.Core.Domain.ARModule 
{ 
using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Drawing; 

/// <summary> 
/// Documentation for the tARReportLogo. 
/// </summary> 
public partial class tARReportLogo : DomainObject<System.Guid> 
{ 
    #region Constructor 
    /// <summary> 
    /// Initializes a new instance of the <see cref="tARReportLogo"/> class. 
    /// </summary> 
    public tARReportLogo() 
    { 
    } 

    /// <summary> 
    /// Initializes a new instance of the <see cref="tARReportLogo"/> class. 
    /// </summary> 
    /// <param name="fReportLogoID">The Payment Type ID.</param> 
    public tARReportLogo(System.Guid fReportLogoID) 
    { 
     this.ID = fReportLogoID; 
    } 

    #endregion   

    #region Properties 

    /// <summary> 
    /// Gets or sets ReportLogoID. 
    /// </summary> 
    public virtual System.Guid fReportLogoID { get; set; } 

    /// <summary> 
    /// Gets or sets Image ID. 
    /// </summary> 
    public virtual System.Guid fImageID { get; set; } 

    /// <summary> 
    /// Gets or sets Image Name. 
    /// </summary> 
    public virtual string fImageName { get; set; } 

    /// <summary> 
    /// Gets or sets Image Value. 
    /// </summary> 
    public virtual Image fImageValue { get; set; }     

    #endregion 

    #region Methods 
    /// <summary> 
    /// Joins a first name and a last name together into a single string. 
    /// </summary>  
    /// <returns>The hash code.</returns> 
    public override int GetHashCode() 
    { 
     return ID.GetHashCode(); 
    } 
    #endregion 
} 
} 

这里是HBM文件

<?xml version="1.0" encoding="utf-8" ?> 
    <hibernate-mapping assembly="BlackOpsP2.Core" namespace="BlackOpsP2.Core.Domain.ARModule" xmlns="urn:nhibernate-mapping-2.2"> 
    <class name="tARReportLogo" table="tARReportLogo" lazy="true" > 
    <id name="fReportLogoID"> 
     <generator class="guid" /> 
    </id>  
    <property name="fImageID"> 
    </property> 
    <property name="fImageName" >  
    </property> 
    <property name="fImageValue" type="Serializable" length="2147483647"> 
    </property>  
    </class> 
</hibernate-mapping> 

我使用NHibernate 3.3版本。

感谢,

+0

任何内部异常? –

+0

{“输入流不是有效的二进制格式,起始内容(字节)为:42-4D-DE-19-00-00-00-00-00-00-36-04-00-00- 28-00-00 ...“} – Awadhendra

回答

3

更改你的C#属性byte[]

public partial class tARReportLogo : DomainObject<System.Guid> 
{ 
    ... 
    public virtual byte[] fImageValue { get; set; } // image as a byte array 
    ... 
} 

你的映射更不需要那么这个

<property name="fImageValue" length="2147483647" /> 

任何其他的转化率(以图片实例或别的什么)你可以在C#中完成。 NHiberante会将byte[]映射到SQL Server中image

+0

当我们将类型从图像更改为字节[]时,我们无法将图像与picturebox控件绑定。我使用数据绑定属性来绑定PictureBox控件中的图像。 – Awadhendra

+1

它只是一个DB部分。 DB'image'类型到C#类型'byte []'的映射。您可以将其标记为受保护的:'protected virtual byte [] fImageValue {get;组; }'并引入'public Image ImageValue {get {..} set {..}}',它将调用* fImageValue *并提供转换。合理? –

相关问题