首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从ICollection实体框架核心加载ICollection

从ICollection实体框架核心加载ICollection
EN

Stack Overflow用户
提问于 2019-05-27 18:51:07
回答 1查看 118关注 0票数 1

我有这些模型,它们都是一对多的连续关系。

ListaAbastecimento > ReferenciaAbastecimento > EtiquetaAbastecimento

代码语言:javascript
复制
[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; }
    }

下面是我尝试过的方法,但是theninclude找不到属性

代码语言:javascript
复制
   var abastecimentosList = await _context.ListasAbastecimento
            .Include(la => la.Referencias)
            .ThenInclude(r => r.Etiquetas) // can't find Etiquetas property
            .ToListAsync();

这不起作用

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-27 19:40:20

实体框架核心本身支持在多对多关系上使用ThenInclude,并且编译器应该能够处理所提供的代码。但是,在Intellisense和Visual Studio中有/曾经有一个bug,它不能正确显示您可以使用的属性。(在您的例子中是Etiquetas)。可以确认,它是在VS 2019 (16.2.0 Preview 1.0)版本中修复的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56324644

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档