Проблема, с которой я столкнулся, заключается в следующем: мне нужно получить несколько свойств навигации, чтобы данные отображались на моем интерфейсе. Я использую .Include(), чтобы получить их. По умолчанию Include выполняет внутреннее соединение, я это понимаю. Я также читал, что если свойства навигации имеют значение NULL, а тип столбца в базе данных может быть NULL, то будет выполнено LEFT JOIN. Мой запрос по-прежнему использует INNER JOIN, хотя оба моих столбца, FK, имеют значение NULL.
Это мой запрос
var listOfProductsOnSets = await productWithSetsRepository
.FindQueryable(asoc => asoc.IdSet == idSet)
.Include(c => c.AsCuloare)
.ThenInclude(cc => cc!.CodCuloare)
.Include(d => d.AsDimensiune)
.AsSplitQuery()
.ToListAsync();
Это мой класс:
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 CombinatieSetPeComanda { get; }
}
А это мои журналы:
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;
Подробнее здесь: https://stackoverflow.com/questions/790 ... -left-join