У меня есть эти модели, все из которых последовательно связаны друг с другом.
ListaAbastecimento > ReferenciaAbastecimento > EtiquetaAbastecimento
[Table(name: "hListasAbastecimento")]
public class ListaAbastecimento
{
public int Id { get; set; }
public int ColaboradorId { get; set; }
[ForeignKey("ColaboradorId")]
public virtual Colaborador Colaborador { get; set; }
public string UAP { get; set; }
public DateTime DataCriacao { get; set; }
public virtual ICollection<ReferenciaAbastecimento> Referencias { get; set; }
}
[Table(name: "hReferenciasAbastecimento")]
public class ReferenciaAbastecimento
{
public int Id { get; set; }
[MaxLength(15)]
public string Referencia { get; set; }
public int? QtdAbastecimento { get; set; }
public int? QtdCaixas { get; set; }
public int? QtdPecasPorCaixa { get; set; }
public virtual ICollection<EtiquetaAbastecimento> Etiquetas { get; set; }
}
[Table(name: "hEtiquetasAbastecimento")]
public class EtiquetaAbastecimento
{
public int Id { get; set; }
public int? EtiquetaFIFO { get; set; }
public int? Qtd { get; set; }
[MaxLength(20)]
public string Localizacao { get; set; }
public int ReferenciaAbstecimentoId { get; set; }
[ForeignKey("ReferenciaAbstecimentoId")]
public virtual ReferenciaAbastecimento ReferenciaAbastecimento { get; set; }
}
Вот что я пробовал, однако theinclude не находит свойства
var abastecimentosList = await _context.ListasAbastecimento
.Include(la => la.Referencias)
.ThenInclude(r => r.Etiquetas) // can't find Etiquetas property
.ToListAsync();
это не работает
Использование ThenInclude
в отношениях «многие ко многим» поддерживается самим Entity Framework Core, и компилятор должен справиться с представленным кодом. Однако в Intellisense и Visual Studio (ах) есть/был ошибка, который неправильно отображал свойства, которые вы могли бы использовать. (в вашем случае Etiquetas
). Могу подтвердить, это исправлено в версии VS 2019 (16.2.0 Preview 1.0).