EF Core Include() not doing LEFT JOIN

The problem i an encountering is this: I need to get multiple navigation properties for the data to display on my frontend. I’m using .Include() to get those.

By default, Include does an inner join, I get that. I also read that if the navigation properties are nullable and the column type in the database can be null, it will do a LEFT JOIN. My query still uses INNER JOIN, even though both my columns which are FK are nullable.

This is my query

var listOfProductsOnSets = await productWithSetsRepository
            .FindQueryable(asoc => asoc.IdSet == idSet)
            .Include(c => c.AsCuloare)
                .ThenInclude(cc => cc!.CodCuloare)
            .Include(d => d.AsDimensiune)
            .AsSplitQuery()
            .ToListAsync();

This is my class :

public class AsociereSeturi
{
    // Attributes
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int IdAsociereSet { get; init; }
    
    // Foreign Keys
    public int IdProdus { get; init; }
    public Produse Produs { get; init; } = null!;
    
    public int IdSet { get; init; }
    public Seturi Set { get; init; } = null!;
    
    public int? IdCuloare { get; init; }
    public Culori? AsCuloare { get; init; } 
    public int? IdDimensiune { get; init; }
    public Dimensiuni? AsDimensiune { get; init; } 
    
    public ICollection<ProduseCuComenzi> CombinatieSetPeComanda { get; } 
}

And these are my logs:

SELECT a.id_asociere_set, a.id_culoare, a.id_dimensiune, a.id_produs, a.id_set, 
       c.id_culoare, c.id_cod_culoare, c.nume_culoare, 
       d.id_dimensiune, d.latime, d.lungime, d.PerdeaEstePereche, d.recomandare_pat
FROM asociere_seturi AS a
INNER JOIN culori AS c ON a.id_culoare = c.id_culoare
INNER JOIN dimensiuni AS d ON a.id_dimensiune = d.id_dimensiune
WHERE a.id_set = @__idSet_0;

EDIT
Configuration
This is the Dimensiuni table

modelBuilder.Entity<Dimensiuni>(entity =>
        {
         
            entity.ToTable("dimensiuni");
            entity.HasKey(e => e.IdDimensiune);

            entity.Property(e => e.IdDimensiune)
                .HasColumnType("integer")
                .HasColumnName("id_dimensiune")
                .HasAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);

            entity.Property(e => e.Lungime)
                .HasColumnType("varchar")
                .HasColumnName("lungime")
                .HasMaxLength(4)
                .IsRequired();
            
            entity.Property(e => e.RecomandarePat)
                .HasColumnType("varchar")
                .HasColumnName("recomandare_pat")
                .HasMaxLength(15);
            
            entity.Property(e => e.Latime)
                .HasColumnType("varchar")
                .HasColumnName("latime")
                .HasMaxLength(4)
                .IsRequired();

            entity.HasMany(e => e.DAsociereSeturi)
                .WithOne(asoc => asoc.AsDimensiune)
                .HasForeignKey(asoc => asoc.IdDimensiune)
                .HasConstraintName("FK_Dimensiune_AsociereSeturi");

            entity.HasMany(e => e.DProduseCuComenzi)
                .WithOne(pc => pc.PcDimensiune)
                .HasForeignKey(pc => pc.IdDimensiune)
                .HasConstraintName("FK_Dimensiune_ProduseComenzi");


        });

This is the Culori table

modelBuilder.Entity<Culori>(entity =>
        {
            entity.ToTable("culori");
            entity.HasKey(e => e.IdCuloare);

            entity.Property(e => e.IdCuloare)
                .HasColumnType("integer")
                .HasColumnName("id_culoare")
                .HasAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);

            entity.Property(e => e.NumeCuloare)
                .HasColumnName("nume_culoare")
                .HasColumnType("varchar")
                .HasMaxLength(20)
                .IsRequired();
            
            entity.Property(e => e.IdCodCuloare)
                .HasColumnName("id_cod_culoare")
                .HasColumnType("integer")
                .IsRequired();

            entity.HasMany(e => e.CAsociereSeturi)
                .WithOne(asoc => asoc.AsCuloare)
                .HasForeignKey(asoc => asoc.IdCuloare)
                .HasConstraintName("FK_Culoare_AsociereSeturi");
            
            entity.HasMany(e => e.CProduseCuComenzi)
                .WithOne(pc => pc.PcCuloare)
                .HasForeignKey(pc => pc.IdCuloare)
                .HasConstraintName("FK_Culoare_ProduseComenzoi")
                .IsRequired();


        });

The relevant parts

// Culori with AsociereSeturi
entity.HasMany(e => e.CAsociereSeturi)
                .WithOne(asoc => asoc.AsCuloare)
                .HasForeignKey(asoc => asoc.IdCuloare)
                .HasConstraintName("FK_Culoare_AsociereSeturi");
// Dimensiuni with AsociereSeturi
  entity.HasMany(e => e.DAsociereSeturi)
                .WithOne(asoc => asoc.AsDimensiune)
                .HasForeignKey(asoc => asoc.IdDimensiune)
                .HasConstraintName("FK_Dimensiune_AsociereSeturi");

EDIT_2
THE PROBLEM!! I FOUND IT!

The problem was that in my AsociereSeturi OnModelCreating i put isRequired.

 entity.Property(e => e.IdSet)
                .HasColumnType("integer")
                .HasColumnName("id_set")
                .IsRequired();
            
            entity.Property(e => e.IdDimensiune)
                .HasColumnType("integer")
                .HasColumnName("id_dimensiune")
                .IsRequired();

REMOVED .IsRequired() and it worked like a charm!

Thank you Steve!

Can you add the configuration that is being used for resolving the relationships and FKs?

EF would not resolve “IdCuloare”, or certainly not “id_culoare” as the FK for a navigation propertynamed AsCuloare of type Culoare by convention. By default it would be looking for “CuloareId” or “Culoare_Id”. There must be some configuration in OnModelCreating or an IEntityTypeConfiguration<Culoare> in the code to configure that association and I suspect you will find it is marking it as .IsRequired(true). Removing that should correct the joining to be optional /w LEFT JOIN.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật