Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public class Student:BaseEntity
{
#region fields
public string StudentID { get; set; }

public string FirstName{get;set;}

public string LastName { get; set; }

public int Age { get; set; }

public string Gender { get; set; }

public string Batch { get; set; }

public string Address { get; set; }




#endregion
}

public virtual IList<student> GetStudentByID()
{

var query = from c in _studentRepository.Table
orderby c.StudentID
select new
{ c.StudentID,
c.FirstName,
c.LastName,
c.Age
};

var details = query.ToList();
return details;

}
Posted

Hi,

Above error is self exploratory,


Solution :

C#
var query = from c in _studentRepository.Table
orderby c.StudentID
select new Student
{ StudentID=c.StudentID,
FirstName=c.FirstName,
LastName=c.LastName,
Age=c.Age
};


it will work.
 
Share this answer
 
Comments
Member 11210682 6-Nov-14 1:50am    
var query = from c in _studentRepository.Table
orderby c.StudentID
select new Student
{ StudentID=c.StudentID,
FirstName=c.FirstName,
LastName=c.LastName,
Age=c.Age
};


After Implementing the Above code it gives error as " Cannot Initialize type 'Student' with a collection initialize beacuse it does not implement 'System.Collections.IEnumerable' "
Suvabrata Roy 6-Nov-14 2:36am    
Please check your Syntax or post the whole code
CSS
var query = from c in _studentRepository.Table
orderby c.StudentID
select new Student
{ StudentID=c.StudentID,
FirstName=c.FirstName,
LastName=c.LastName,
Age=c.Age
};



After Implementing the Above code it gives error as " Cannot Initialize type 'Student' with a collection initialize beacuse it does not implement 'System.Collections.IEnumerable' "
 
Share this answer
 
Comments
BillWoodruff 6-Nov-14 7:32am    
Please enter comments/responses you have to solutions, or comments, as comments on the solution or comment, not as separate "solutions," as you have done here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900