SQL FileStream + Entity Framework存储大文件 [英] SQL FileStream + Entity Framework store large files

查看:75
本文介绍了SQL FileStream + Entity Framework存储大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想在filestream列中存储文件时,我总是需要将整个二进制文件读入内存:

When i want to store a file in a filestream column, i always need to read the whole binary into the memory:

using (MemoryStream memoryStream = new MemoryStream())
{
   sourceStream.CopyTo(memoryStream);
   binaryStore.Content = memoryStream.ToArray(); //Content = filestream column
}

实体框架是否可以直接放流?因为,如果我要上传大文件,则会收到OutOfMemoryException。

is there a way with the entity framework, to put the stream directly? Because, if i want to upload a large file, i get a OutOfMemoryException.

推荐答案

没有看到有关FILESTREAM支持的任何更新在EF中。 (之前提到作为.net 3.5 sp1版本的部分支持 此处)。我想实体框架正在通过TSQL访问FILESTREAM,显然您将无法获得FILESTREAM的流传输性能优势。 (需要将所有文件内容读入内存

Didn't see any update about FILESTREAM support in EF. (Mentioned before as partial support with .net 3.5 sp1 release here). I suppose entity framework is accessing FILESTREAM through TSQL and apparent that you will not be able to get the streaming performance benefits of FILESTREAM. (need to read all file content into memory)

因此,推荐的方法是与 SqlFileStream .Net API。

So, the recommended approach is using with SqlFileStream .Net API.

http://lennilobel.wordpress.com/2011/08/22/using-sqlfilestream-in-c-to-access-sql -server-filestream-data /

这篇关于SQL FileStream + Entity Framework存储大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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