none
System.out.of.memory issue with eager loading RRS feed

  • Question

  • Hi,

    I have an out of memory exception when I'm trying to iterate a LINQ query result.
    Here is my model:

    public class Model 
    {
    	public int Id { get; set; }
    	public ICollection<ModelLine> ModelLines { get; set; }
    }
    		
    // Around 800 lines for a model
    public class ModelLine
    {
    	public int Id { get; set; }
    	public int BlocId { get; set; }
    	public Bloc Bloc { get; set; }
    }
    
    
    
    public class Bloc
    {
    	public int Id { get; set; }
    	public ICollection<BlocLine> BlocLines { get; set; }
    	public ICollection<Translation> Translations { get; set; }
    }
    
    // Around 20 lines for a bloc 	
    public class BlocLine
    {
    	public int Id { get; set; }
    	public int BlocId { get; set; }
    	public int? ArticleId { get; set; }
    	
    	public Bloc Bloc{ get; set; }
    	public Article Article { get; set; }
    }
    
    
    public class Article
    {
    	public int Id { get; set; }
    	public string Code { get; set; }
    	public ICollection<Translation> Translations { get; set; }
    }

    For a given Model, I have to iterate every ModelLine, BlocLine and Article (only in read access).
    I'm trying to eager load a model this way :

    DbContext.Configuration.ProxyCreationEnabled = false;
                DbContext.Configuration.LazyLoadingEnabled = false;
    			
                var query = this.DbContext.Models.AsNoTracking()
                    .Include(m => m.ModelLines.Select(ml => ml.Bloc.Translations))
                    .Include(m => m.ModelLines.Select(ml => ml.Bloc.BlocLines.Select(bl => bl.Article.Translations)))
    				.FirstOrDefault(m => m.Id == id);
    				


    I also have an exception when I lazy load the data.
    What is the best practice to do this ? Should I divide my query into several queries ?

    Thanks in advance for your help

    Thursday, April 21, 2016 11:47 PM

Answers

All replies