2016-07-10 73 views
0

這似乎是這樣一個基本概念,但由於某種原因,它完全躲過了我。具有多個子記錄的父模型

父模型

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

就像我說的,我確定它的基本的東西,但當我能弄明白的時候。

對此提出建議?

+0

';'? –

+1

Doh!添加了使用語句,並將其清除。但是,我確實需要按照上述編輯中的說明更改我的模型,以使其正常工作 –

回答

0

父類必須有兒童使用System.Data.Entity的兒童的List。IQueryable的

public class Parent 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public List<Child> Children { get; set; } 
} 
相關問題