efcore: Collection navigation property, some items are not loaded in the model

I am applying convention relationships at Entity Framework Core 1 2

. When I try to load a navigation property of type “collection”, some items are loaded, others are not. I load it in the following way:

                result = ctx.Instrumentos
                    .Include(m => m.Materia)
                    .Include(c => c.Curso)
                .Where(i => i.CreateUserId == userId && i.AnhoLectivo == anhoLectivo && i.Etapa == etapa).ToList();  

EFC generates the SQL query (with inner join) perfectly, and the SQL query returns the expected values (if I run the query directly in SQL Management Studio), however EFC does not load all the navigation properties correctly ( see attached files)

Steps to reproduce

public class Instrumento : EntityBase
    {  
        public Int64 InstrumentoId { get; set; }
        public string Seccion { get; set; }
        public string Nombre { get; set; }       
        public int AnhoLectivo { get; set; }       
        public int Etapa { get; set; }
        public Curso Curso { get; set; }
        public Materia Materia { get; set; }
    }

 public class Materia
    {
        public long MateriaId { get; set; }
        public string Nombre { get; set; }     
        [JsonIgnore]
        public List<Instrumento> Instrumentos { get; set; }
    }
public class Curso
    {
        public Int64 CursoId { get; set; }
        public String CodigoUsuario { get; set; }
        public Int64 NivelId { get; set; }
        public String Nombre { get; set; }       
        [JsonIgnore]
        public List<Instrumento> Instrumentos { get; set; }        
    }

Nothing in OnModelCreating () and nothing special (except logger and connection string) in OnConfiguring ().

I did not create any migration since the database already exists in production. I am just creating the models and adapting it to the current database simulating Code First.

I have tried configuring Microsoft.EntityFrameworkCore.Proxies without success.

Further technical details

EF Core version: 3.1.3 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET Core 3.1 Operating system: Windows 10 PRO x64 IDE: Visual Studio 2019 16.5.4 1 2

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (12 by maintainers)

Most upvoted comments

@GustavoArriola any chance you can post a small, runnable code sample that demonstrates the issue? It’s bit hard to understand what’s going on from a series of screenshots…