entity framework 4 - sub query within linq select statement -


i want list of student details , attended hours using linq query in entity framework.

i using following query bind list of students details , total hours attended them .

var students = (from pa in db.tblstudents                 select new studentmodel                 {                     name = pa.name,                     studentid = pa.id,                     rollno = pa.rollno,                     department = pa.department,                     phone = pa.phone,                     address = pa.address,                     totalhours = (from time in tblhours                                    time.studentid = pa.id                                    select time.hours).sum()                 }).distinct().asqueryable().tolist();  studentmodel looks below:-  public class studentmodel  { public string name { get; set; }  public int studentid { get; set; }  public string rollno{ get; set; }  public string department{ get; set; }  public long phone{ get; set; }  public string address{ get; set; }  public string address2{ get; set; }  public decimal totalhours{ get; set; }  }  

tblhours , tblstudent related studentid , if want hours attended students within particular timeperiod how can that?

i error "only parameterless constructors , initializers supported in linq entities" when try above query

i think going wrong when selecting total hours using subquery...

make sure have empty constructor in studentmodel class

btw, if set relationship should able well

totalhours = pa.tblhours.sum(time=>time.hours) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -