开发者

Entity SQL - Retrieves bytes data in chunks

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:

  1. Query the data with your qualifying criteria that return a reference to what needs to be loaded, then stream in from there afterwards.

  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜