我有以下型号:继承和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