Large files are stored using SQL FileStream and Entity Framework.

entity-framework filestream

Question

I always have to read the whole binary into memory when I want to save a file in a filestream column:

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

Is it possible to insert the stream directly using the entity framework? Because I get an OutOfMemoryException while attempting to upload a huge file.

1
9
4/7/2012 2:26:41 PM

Accepted Answer

I didn't see any updates regarding EF's FILESTREAM support. (formerly mentioned as limited support with the release of.net 3.5 sp1here). I assume entity framework accesses FILESTREAM via TSQL, and it is obvious that you will not be able to take use of FILESTREAM's advantages for streaming performance. (All file content must be read into memory.)

the suggested course of action is to use withSqlFileStream The.Net API

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

3
4/7/2012 4:34:48 PM

Popular Answer

There is no support in EF forFIlESTREAM It manages all communications withFILESTREAM as usualVARBINARY(MAX) column, therefore you must use ADO.NET directly if you wish to utilize streaming.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow