Entity Framework - Data Access Tips

3

I'm working on a project using EF6 with C #, in one of my classes I have to save a file, example below:

   public partial class Arquivo
    {
        [Key]
        public int ArquivoID { get; set; }

        public string Nome { get; set; }
        public byte[] ArquivoFisico { get; set; }
        public string TipoArquivo { get; set; }
     }

My problem is in the arquivofisico property when I query data from other classes that are bound to this one I would not like to load the arquivofisico property, as I can have 5, 10 MB files, my server's memory goes popping up if I have too many classes ... I want to access this property only when I use a generic handler to download. Do you have any tips for doing this or do I have to use lazy loading anyway?

Thanks for the help.

    
asked by anonymous 25.02.2016 / 21:47

1 answer

2
  

Do you have any tips for doing this or do I have to use lazy loading anyway?

Do not materialize the column by selecting. Do as follows:

var arquivos = db.Arquivos
                 .Where(...)
                 .Select(a => new { 
                                    a.ArquivoID, 
                                    a.Nome, 
                                    a.TipoArquivo })
                 .ToList();
    
25.02.2016 / 22:00