gpt4 book ai didi

c# - Nhibernate 无法反序列化可序列化的属性

转载 作者:行者123 更新时间:2023-11-30 22:21:24 26 4
gpt4 key购买 nike

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

我查看了 stackoverflow 和 google 上的一些链接,但似乎对我没有任何帮助。

这里我给出了示例 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 版。

谢谢,

最佳答案

将您的 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# 中执行的任何其他转换(到 Image 实例或其他)。 NHiberante 会将 byte[] 正确映射到 SQL Server image

关于c# - Nhibernate 无法反序列化可序列化的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14398801/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com