这看起来像是一个基本概念,但出于某种原因,它完全躲过了我。
父模型
public class Parent
{
public int Id { get; set; }
public string Name { get; set; }
public IQueryable<Child> Children { get; set; } <-- removed this line
public List<Child> Children { get; set; } <-- added this line
}
儿童模特
public class Child
{
public int Id { get; set; }
public int ParentId { get; set; }
public string SomeStringVar { get; set; }
}
我想通过简单地运行
var parents = _context.Parents.Include(c => c.Children).ToList();
将返回包含所有父项的所有父项的列表,但lambda表达式错误输出错误Cannot convert the lambda expression to type string
。
就像我说的那样,我确定它是基本的东西,但是如果我能弄明白的话就是dang。
建议?
答案 0 :(得分:0)
您的父班必须将儿童列为儿童名单而不是IQueryable
public class Parent
{
public int Id { get; set; }
public string Name { get; set; }
public List<Child> Children { get; set; }
}