惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
小众软件
小众软件
F
Fortinet All Blogs
爱范儿
爱范儿
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
C
Check Point Blog
博客园 - 聂微东
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
Vercel News
Vercel News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
About on SuperTechFans
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
宝玉的分享
宝玉的分享
Jina AI
Jina AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - mahope

一个算法题解 在ASP.NET web 站点中使用log4net (1.2.9) 在.NET 中实现 AOP 解决Web Service中传递子类实例时,序列化的问题。 Q & A:Does ASP.NET support one-way Web Service operations? openwave:Malformed server response web 项目的 csproj 文件要有对应的.webinfo文件才能在vs里面打开 - mahope 软件需求规范(SRS)指南 写需求文档的一般原则 删除everyone对c:的 访问权限后,运行asp.net出现DirectoryNotFoundException未找到路径“C:\”的一部分 - mahope - 博客园 NHibernate.ADOException : Unable to perform find 对于事件不能调用BeginInvoke,可改用另外一层包装 IBM面试题试解(关于50条狗、50个人、病狗) Einstein's Riddle 爱因斯坦出的智力题? Artificial intelligence: Solving problems for the real world 一些面向对象的设计法则 重构、分支语句、虚函数、抽象函数与多态--《重构:改善既有代码设计》之读书心得 NHibernate 执行内嵌类(Nested Class)查询 为内嵌类(Nested Class)配置NHibernate的O/R Mapping文件
NHibernate Mapping文件中如何指定类的字节数组属性
mahope · 2005-12-09 · via 博客园 - mahope

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

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

public class Employee
 
{
//其他略去
  public byte[] Photo
  
{
   
get
   
{
    
return _photo;
   }

   
set
   
{
    _photo 
= value;
   }

  }

}

在影射文件中可以用 BinaryBlob 类型:

<class name="Employee" table="[Employee]"> 
        
<id name="ID" column="EmployeeID" unsaved-value="0"> 
            
<generator class="native" /> 
</id>
<!--其他略去--> 
    
<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要面对的新需求。