Entity Framework - Data Access Tips

Asked

Viewed 77 times

3

I am 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 property arquivofisico when I consult data from other classes that are linked to this would not like it to load the property arquivofisico, because I can have files of 5, 10 MB, the memory of my server will burst if there are many classes... I want to access this property only when using a Handler generic to download. Have any hints to do this or I have to use Lazy loading same?

Thanks for the Help.

1 answer

2


Have any hints to do this or I have to use Lazy loading same?

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

var arquivos = db.Arquivos
                 .Where(...)
                 .Select(a => new { 
                                    a.ArquivoID, 
                                    a.Nome, 
                                    a.TipoArquivo })
                 .ToList();
  • Thank you for the answer! Interesting, but I forgot to mention that I am using a generic repository to search the data there I believe that the thing changes a bit of figure... I use the get method as below: Iqueryable<Tentity> Get(Func<Tentity, bool> predicate);

  • Get rid of your generic repository. It is useless. See more here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.