使用NHibernate保留Blob流 [英] Persisting Blob Streams with NHibernate

查看:103
本文介绍了使用NHibernate保留Blob流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个声明为的类:

If I have a class declared as:

public class MyPersistentClass
{
     public int ID  { get; set; } 
     public Stream MyData  {get;set; }
}

如何使用NHibernate的映射在数据库之间来回保留MyData属性?

How can I use NHibernate's mappings to persist the MyData property to and from the database?

推荐答案

您可以使用具有自定义类型的Stream并根据您的存储需求进行映射.但是,正如我在

You could use a Stream using a custom type and map it according to your storage needs. But there are some issues with using the Stream object as I mention in my blog series about lazy streaming of BLOBs and CLOBs with NHibernate.

您真正需要的是一个Blob对象,该对象又可以创建一个Stream来读取数据.由于Stream包含有关您正在读取的职位的信息,并且预计将被关闭和处置,因此直接在域模型中使用时,可能会产生一些问题.

What you really need is a Blob object that in turn can create a Stream to read data from. Since Stream contains information about the position you're reading from and expects to be closed and disposed of it can create some issues when used directly in a domain model.

我建议您看看 NHibernate.Lob项目.它包括针对此问题的各种映射选项.到目前为止,几乎没有记录,但是还会有更多记录.

I would suggest that you take a look at the blog series as well as the source code of the NHibernate.Lob project. It includes various mapping options for just such a problem. A little scarcely documented so far but more is coming.

这篇关于使用NHibernate保留Blob流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆