0

I have these two models which are mapped to SQL tables using EF Core code first:

public class Profile
{
 public int ID { get; set; }
 public string FirstName { get; set; }
 public string LastName { get; set; }
 public IEnumerable<Attachment> Attachments { get; set; }
 // Other props
}

public class Attachment
{
 public int ID { get; set; }
 public int ProfileId { get; set; }
 public Profile Profile { get; set; }
 public string FileName { get; set; }
 public byte[] BinaryContent { get; set; }
}

I am trying to fetch these data like this:

 var profileWithAttachments = await _context.Profiles.Include(x => x.Attachments)
                        .Where(x => x.ID == profileId)
                        .ToListAsync();

It takes too long to load for example a query which returns about 80 rows, each of them containing varbinary data to about 100kb takes about 30 seconds. Important to know is that executing this query on SQL Server takes only 2 seconds! I also have tried using Dapper or plain ADO.NET but same results. The issue normally seems to be the BinaryContent column because if I exclude this column it takes less than a second. Are there any solutions to these problem or just saving to the file system or blob storage is the only way to go probably?

Muhamed Krasniqi
  • 1,134
  • 1
  • 13
  • 20
  • Include the SQL query you executed to determine it takes 2 seconds? – Stu Sep 29 '21 at 12:06
  • Yes exactly only 2 seconds, I inspected the generated sql and executed it. – Muhamed Krasniqi Sep 29 '21 at 12:57
  • May well be [this](https://stackoverflow.com/a/28619983/4137916) (old issue, but apparently [still not fixed](https://github.com/dotnet/ef6/issues/88) since it's a tough thing to do and resides in the bowels of the ADO.NET classes, so EF has only limited blame). – Jeroen Mostert Sep 29 '21 at 13:54

0 Answers0