Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirstOrDefaultAsync and binary data #23521

Closed
TeamLucky7 opened this issue Nov 28, 2020 · 2 comments
Closed

FirstOrDefaultAsync and binary data #23521

TeamLucky7 opened this issue Nov 28, 2020 · 2 comments

Comments

@TeamLucky7
Copy link

Hi,

In my project files are stored in database (SQL Server). A column, that stores content of the files, is type of varbinary(MAX).

C# class that represents table with files is following

internal class ApplicationFile
{
    public int ApplicationFileId { get; set; }
    public int ApplicationVersionId { get; set; }
    public virtual ApplicationVersion ApplicationVersion { get; set; }
    public string Name { get; set; }
    public byte[] Content { get; set; }
}

I use following code to fetch data with content of the file:

ApplicationVersion latestApplicationVersionEntity = await Context.ApplicationVersions.FirstAsync(x => x.ApplicationId == applicationEntity.ApplicationId && x.ApplicationVersionId == applicationEntity.CurrentVersionId);
ApplicationFile applicationFileEntity = await Context.ApplicationFiles.FirstOrDefaultAsync(x => x.ApplicationVersionId == latestApplicationVersionEntity.ApplicationVersionId);

The code works fine when file is small (like 100kb), but when the content of the file is bigger than 50MB, then the second line of the code never ends (I waited for result more than 1 hour and I stopped after that time). One core of CPU works with full power all the time, but the execution of the line is endless.

When I replace

ApplicationFile applicationFileEntity = await Context.ApplicationFiles.FirstOrDefaultAsync(x => x.ApplicationVersionId == latestApplicationVersionEntity.ApplicationVersionId);

with

ApplicationFile applicationFileEntity = Context.ApplicationFiles.FirstOrDefault(x => x.ApplicationVersionId == latestApplicationVersionEntity.ApplicationVersionId);

then execution takes less than some seconds.

EF Core version: 5.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.8.2

@roji
Copy link
Member

roji commented Nov 29, 2020

Duplicate of dotnet/SqlClient#593

@roji roji marked this as a duplicate of dotnet/SqlClient#593 Nov 29, 2020
@roji
Copy link
Member

roji commented Nov 29, 2020

This is an issue with SqlClient rather than with EF Core. As you've noticed, the recommended workaround is currently to use synchronous I/O.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants