c# - Entity Framework Mysql 嵌套属性

标签 c# mysql entity-framework-6

我有这个类结构。当我做一些选择时,我收到异常错误。

public class A
{
    public int AId { get; set; }
    public virtual ICollection<B> B { get; set; }
}

public class B
{
    public int BId { get; set; }
    public virtual C C { get; set; }

    public int AId { get; set; }
    public virtual A A { get; set; }
}

public class C // Manifiesto carga
{
    [Key]
    [ForeignKey("B")]
    public int CId { get; set; }

    public virtual B B { get; set; }
    public virtual ICollection<D> D { get; set; }
    public virtual ICollection<E> E { get; set; }
}

public class D
{
    public int DId { get; set; }
    public string Nombre { get; set; }

    public int CId { get; set; }
    public virtual C C { get; set; }
}

public class E
{
    public int EId { get; set; }
    public string Nombre { get; set; }

    public int CId { get; set; }
    public virtual C C { get; set; }
}


    context.AA
                .Include(e => e.B.Select(s => s.C.D))
                .Include(e => e.B.Select(s => s.C.E)).FirstOrDefault(e => e.AId == 1);

我迷路了,我该怎么办?或者我哪里失败了?

谢谢。

(对不起我的英语)

Image exception

在上图中您可以看到异常消息。

最佳答案

当您将父级也放入 DE 时,问题是否已解决

public class D {
   public virtual C C {get;set;}
}
public class E {
   public virtual C C {get;set;}
}

关于c# - Entity Framework Mysql 嵌套属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46888881/

相关文章:

c# - SQLException : Cannot insert duplicate key row in object 'dbo.Users' with unique index

c# - finally block 是没有意义的吗?

php - utf8 字符集和丑陋的大方 block ?

c# - 确定路径的现有目录

Python dict 到 MySQL 中executemany

mysql - 尝试为 rails 安装 mysql 支持时出错

c# - Entity Framework DbContext 如何将记录加载到内存中

c# - 事件 Azure Sql 连接数超过连接池限制

c# - 我如何获得 Visual Studio 解决方案来构建 MVC 项目并将其运行到另一个文件夹?

c# - Asp.net core中如何在ViewComponent之间共享ViewData