【发布时间】:2019-03-17 08:12:23
【问题描述】:
我有 3 张桌子
Inventarios -> Localizacoes -> Etiquetas
从左到右都有一对多的关系
问题是我似乎无法达到礼仪
// GET: api/Inventarios
public IQueryable<Inventario> GetInventarios()
{
var inventarios = db.Inventarios.Include(i => i.Localizacoes.Select(l =>
l.Etiquetas.SelectMany(e => e.Numero)));
return inventarios;
}
这里是模型
public class Inventario
{
public int InventarioID { get; set; }
public string Colaborador { get; set; }
public string Armazem { get; set; }
public decimal Total { get; set; }
public DateTime Data { get; set; }
public ICollection<Localizacao> Localizacoes { get; set; }
}
public class Localizacao
{
public int LocalizacaoID { get; set; }
public string Referencia { get; set; }
public int EtiquetasPorInventariar { get; set; }
public int EtiquetasInventariadas { get; set; }
public bool IsValid { get; set; }
public decimal Precisao { get; set; }
public int InventarioID { get; set; }
public Inventario Inventario { get; set; }
public ICollection<Etiqueta> Etiquetas{ get; set; }
}
public class Etiqueta
{
public int EtiquetaID { get; set; }
public string Numero { get; set; }
public int LocalizacaoID { get; set; }
public Localizacao Localizacao { get; set; }
}
这是我从 api 请求进入浏览器控制台的异常
"包含路径表达式必须引用导航属性 在类型上定义。使用虚线路径进行参考导航 属性和用于集合导航的 Select 运算符 属性。”
【问题讨论】:
-
SelectMany看起来不正确,而且您返回IQueryable的事实也很可疑 -
为什么会这样?我认为它是从 Controller 类生成的,但我不记得了
-
从您的问题中不清楚您到底想得到什么? 所有行来自
Etiqueta?您没有任何where子句。
标签: c# entity-framework