c# - Inheritance and Linq-to-Entities -
i have following models:
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; }
i have following code:
schoolbus schoolbus = new schoolbus(); schoolbus.riders = new list<person> { new student { name = "jim" }, new student { name = "jane } } var query = rider in schoolbus.riders select new { (rider student).studentid; }
students , person set separate tables , i'm using dbcontext.
i know why not work, possible solutions me return right studentid using person collection?
try this:
var studentids = rider.oftype<student>().select(x => x.studentid);
Comments
Post a Comment