概述
有这样一个需求需要管理企业内网的信息,包括图标和链接。考虑到图标也不是很大所以就将图片直接保存在数据库中了。
但是用到Nhibernate,如何映射呢?
Table 5.5. Large Object Mapping Types
NHibernate Type | .NET Type | Database Type | Remarks |
---|---|---|---|
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[]字节数组。
总结
记录项目中遇到的问题,记录点点滴滴。