The following code retrieves all bytes data at once.
I'm wondering how to access byte data stored in chunk using entity framework. Since files are so big (around 50MB), I want to send it to user by chunks as soon as I get partial bytes from database.
using (Entities context = new Entities(EntitiesConnectionString))
{
byte[开发者_如何学编程] data = context.MyFileTable
.Where(item => item.FileId == 1)
.Select(item => FileData)
.FirstOrDefault();
}
Thanks in advance!
It is not possible. EF and LinQ in general enumerates from a source. It will only ever yield complete objects from that source.
I have 2 possible solutions:
Query the data with your qualifying criteria that return a reference to what needs to be loaded, then stream in from there afterwards.
Write a wrapper class that implements IEnumerable, let this return your data along with a stream object you can then interrogate. You can then query this object, and have the stream available to you on the result set.1.
Option #1 is probably the easiest.1.
精彩评论