My doubt is simple. I’m creating a query using LINQ to ENTITIES.
I want to expose a property where returns the query.
I.E.
public ... GetScores
{
get { from e in Exams
select new { .. }
}
I do this to show the data in a datagrid and a graphic. But the problem is I need to especify the datatype like IEnumerable, so at this case T is an class where is anonymous.
Is necessary that I create a class where contains the properties of the query?
Real example
List<Student> studentList = new List<Student>()
{
new Student() { Name="Oscar", ExamResults = new List<float>() {0.8f, 0.75f, 0.6f, 0.95f }},
new Student() { Name="Juan", ExamResults = new List<float>() {0.4f, 0.6f, 0.7f }},
};
var query = from s in studentList
select new
{
Name = s.Name,
Avg = s.ExamResults.Average(),
Description = string.Format("{0} of {1} accredited.", s.ExamResults.Count(e => e > 0.7f), s.ExamResults.Count)
};
public class Student
{
public string Name {get;set;}
public List<float> ExamResults { get; set;}
}
Have you tried: