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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -