实体框架核心渴望加载 - 包括多个级别

时间:2016-11-04 21:23:22

标签: c# entity-framework entity-framework-core

我正在使用Entity框架Core,我有以下模型类。

class A {
    [Key]
    public string AId { get; set; }
    ....
    public List<A_B> A_Bs { get; set; }
}
class A_B {
    [Key]
    public String AId { get; set; }
    [Key]
    public Int16 BId { get; set; }
    [ForeignKey("BId")]
    public B B { get; set; }
}
class B {
    [Key]
    public Int16 Id { get; set; }
    .... // Other properties of B
}

根据此页面https://docs.efproject.net/en/latest/querying/related-data.html,以下代码应该有效。

context.A
    .Include(e => e.A_Bs)
    .ThenInclude(x => x.B) // x has the type of List<A_B> instead of A_B

但是,x的类型为List<A_B>且不具有B的属性?

0 个答案:

没有答案