[NHibernate]Nhibernate如何映射sqlserver中image字段

概述

有这样一个需求需要管理企业内网的信息,包括图标和链接。考虑到图标也不是很大所以就将图片直接保存在数据库中了。

但是用到Nhibernate,如何映射呢?

Table 5.5. Large Object Mapping Types

NHibernate Type.NET TypeDatabase TypeRemarks
StringClob System.String DbType.String type="StringClob" must be specified. Entire field is read into memory.
BinaryBlob System.Byte[] DbType.Binary type="BinaryBlob" must be specified. Entire field is read into memory.
Serializable Any System.Object that is marked with SerializableAttribute. DbType.Binary type="Serializable" should be specified. This is the fallback type if no NHibernate Type can be found for the Property.

解决如下

原hbm.xml

 <property   name="logo" type="byte[]">
             <column name="logo" length="2147483647" sql-type="image" not-null="false"/>
         </property>

改为

 <property   name="logo" type="BinaryBlob">
             <column name="logo" length="2147483647" sql-type="image" not-null="false"/>
         </property>

c#代码中仍然使用byte[]字节数组。

总结

记录项目中遇到的问题,记录点点滴滴。

posted @   wolfy  阅读(1527)  评论(1编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
点击右上角即可分享
微信分享提示