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
}
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.
EF doesn't have any support for FIlESTREAM
. It handles all interactions with FILESTREAM
as normal VARBINARY(MAX)
column so if you want to use streaming you must use ADO.NET directly.
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)
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With