从Avoiding the LOH when reading a binary
跟进在Nhibernate中,是否可以将Stream
保存到数据库中?
使用以下代码,打开FileStream并以2kb块读取其内容:
using (var fs = new FileStream(path, FileMode.Open))
{
byte[] buffer = new byte[2048];
int bytesRead;
while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
{
//// somehow push the contents of the buffer to the database
}
}
通常对象在一个操作中持久化,可以逐步完成吗?