对于字节数组类型的属性映射,可以用Byte[]指定其Type,但是这中类型只能保存8000个字节(虽然你可以指定超过8000的Length属性,而且生成的表字段类型也为Image)。 如果要保存任意长的字节数据,需要用到BinaryBlob类型。

举个例子,如果Employee类有一Photo属性为字节数组:

NHibernate Mapping文件中如何指定类的字节数组属性public class Employee
}

在影射文件中可以用 BinaryBlob 类型:
NHibernate Mapping文件中如何指定类的字节数组属性<class name="Employee" table="[Employee]"> 
NHibernate Mapping文件中如何指定类的字节数组属性        
<id name="ID" column="EmployeeID" unsaved-value="0"> 
NHibernate Mapping文件中如何指定类的字节数组属性            
<generator class="native" /> 
NHibernate Mapping文件中如何指定类的字节数组属性
</id>
NHibernate Mapping文件中如何指定类的字节数组属性
<!--其他略去--> 
NHibernate Mapping文件中如何指定类的字节数组属性    
<property name="Photo" column="[Photo]" not-null="false"  type="BinaryBlob"/>    </class> 

另外,其他大对象的映射可参考下表:
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.

字节数组可以持久化之后,自然会担心内存占用问题。那么能不能对属性也做Lazy Initialization的实现呢?这可能是NHibernate要面对的新需求。

相关文章:

  • 2022-12-23
  • 2021-07-10
  • 2022-01-17
  • 2021-05-17
  • 2021-07-21
  • 2021-09-15
  • 2022-12-23
  • 2021-09-10
猜你喜欢
  • 2022-12-23
  • 2021-06-06
  • 2022-02-01
  • 2021-11-21
  • 2021-09-21
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案