我有以下型號:繼承和LINQ到實體
public class Person
{
long Id;
string name;
}
public class Student : Person
{
string studentId;
}
public class Bus
{
long Id;
public ICollection<Person> riders {set; get;}
}
public class SchoolBus : Bus
{
long schoolBusNumber;
}
我也有下面的代碼:
SchoolBus schoolBus = new SchoolBus();
schoolBus.riders = new List<Person>
{
new Student { name = "Jim" },
new Student { name = "Jane }
}
var query = from rider in SchoolBus.riders
select new
{
(rider as Student).studentId;
}
學生和人都設置爲單獨的表,我使用DbContext。
我知道爲什麼這不起作用,但有什麼可能的解決方案讓我通過使用Person集合返回正確的studentId?
結果懶惰加載讓我。需要使用Include()來包含我需要加載的屬性。 – khaihon 2012-03-08 22:57:23