Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

left join, bug when show data #6232

Closed
JuanIrigoyen opened this issue Aug 3, 2016 · 2 comments
Closed

left join, bug when show data #6232

JuanIrigoyen opened this issue Aug 3, 2016 · 2 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@JuanIrigoyen
Copy link

JuanIrigoyen commented Aug 3, 2016

Steps to reproduce

1 - Create two entities with next structure.

public partial class Centros_trabajo_agrupacion
    {
        public Centros_trabajo_agrupacion()
        {
            Centros_trabajo = new HashSet<Centros_trabajo>();
        }
        public string Agrupacion { get; set; }
        public string Descripcion { get; set; }
        public string Observaciones { get; set; }

        public virtual ICollection<Centros_trabajo> Centros_trabajo { get; set; }
    }

public partial class Centros_trabajo
    {
        public string Codigo { get; set; }
        public string Descripcion { get; set; }
        public string Almacen { get; set; }
        public string Ubicacion { get; set; }
        public long Capacidad_diaria { get; set; }
        public string Tipo { get; set; }
        public string Observacion { get; set; }
        public string Agrupacion { get; set; }

        public virtual Centros_trabajo_agrupacion AgrupacionNavigation { get; set; }
    }

2 - Create context:

public partial class Maldivas_oranContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
             optionsBuilder.UseSqlServer(@"Server=Sealand;Database=Maldivas_oran;User Id=test;Password=***");
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Centros_trabajo>(entity =>
            {
                entity.HasKey(e => e.Codigo)
                    .HasName("PK_Centros");

                entity.ToTable("Centros_trabajo", "Produccion");
                entity.Property(e => e.Codigo).HasColumnType("nchar(6)");
                entity.Property(e => e.Agrupacion).HasColumnType("nchar(6)");
                entity.Property(e => e.Almacen).HasColumnType("nchar(3)");
                entity.Property(e => e.Capacidad_diaria).HasDefaultValueSql("288000000");
                entity.Property(e => e.Descripcion).HasMaxLength(200);
                entity.Property(e => e.Tipo).HasColumnType("nchar(3)");
                entity.Property(e => e.Ubicacion).HasColumnType("nchar(5)");

                entity.HasOne(d => d.AgrupacionNavigation)
                    .WithMany(p => p.Centros_trabajo)
                    .HasForeignKey(d => d.Agrupacion)
                    .HasConstraintName("FK_Centros_trabajo_Centros_trabajo_agrupacion");
            });

            modelBuilder.Entity<Centros_trabajo_agrupacion>(entity =>
            {
                entity.HasKey(e => e.Agrupacion)
                    .HasName("PK_Centros_trabajo_agrupacion");

                entity.ToTable("Centros_trabajo_agrupacion", "Produccion");
                entity.Property(e => e.Agrupacion).HasColumnType("nchar(6)");
                entity.Property(e => e.Descripcion).HasMaxLength(200);
                entity.Property(e => e.Observaciones).HasColumnType("ntext");
            });
        }

        public virtual DbSet<Centros_trabajo> Centros_trabajo { get; set; }
        public virtual DbSet<Centros_trabajo_agrupacion> Centros_trabajo_agrupacion { get; set; }

  1. Add data and execute this query:

    using (Maldivas_oranContext context = new Maldivas_oranContext())
              {
    
                  var qprevius =
                          from c in context.Centros_trabajo
                          join d in context.Centros_trabajo_agrupacion on c.Agrupacion equals d.Agrupacion into gj
                          where c.Agrupacion == "AG0S01" && c.Capacidad_diaria > 0
                          from dgp in gj.DefaultIfEmpty()
    
                          select new
                          {
                              Centro = c.Codigo,
                              Descripcion = dgp == null ? c.Descripcion : dgp.Descripcion,
                              Agrupacion = c.Agrupacion,
                              Activo = true,
                              Capacidad_diaria = c.Capacidad_diaria
                          };
    
                  var result = qprevius.ToList();
    
                  -- debug result
                 }
    }
    

The issue

When I run a query with left outer join, this does not show the data correctly ,

  1. The sample query in LinPad5 returns the values correctyl
  2. In Sql query runs correctly, but duplicate the ' Agrupacion ' field
  3. When displaying data C # debug program, This step shows the wrong result.

Further technical details

EF 7

Attach images.

linqpad5
linqsql
linqc

@divega divega added this to the 1.1.0 milestone Aug 3, 2016
@maumar
Copy link
Contributor

maumar commented Aug 19, 2016

Same root cause as #6318, reassigning to @smitpatel since he is working on it already

@smitpatel
Copy link
Contributor

fixed via 5953d96

@smitpatel smitpatel added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug and removed type-investigation labels Aug 29, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants