Question

In Linq i must create a query with method only, i've got 2 tables :

  • Students (LastName, FirstName, Result)
  • Grades (Max, Min, Name)

I must select students (LastName, FirstName) and add to it the grade (Result > Min && Result < Max).

In the end I must have :

IEnumerable<T> T => LastName, FirstName, Grade

I try this :

var SAG = dc.Students
            .Where(w => w.Year_Result >= 12)
            .Join(dc.Grades, s => true, g => true, (s, g) => 
                  new { s.LastName, 
                        s.FirstName, 
                        Grade = g.Name
                                 .Where(w => (w.Min < s.Result) 
                                          && (w.Max > s.Result))
                        .FirstOrDefault() }).ToList();

But with this request I've only 2 results but I must have 40 results.

Was it helpful?

Solution

Would this work for you?

var SAG =
    from s in dc.Students
    from g in dc.Grades
    where g.Min < s.Result
    where g.Max > s.Result
    select new
    {
        s.LastName, s.FirstName, Grade = g.Name,
    };

(I do suspect you need either <= or >= in there somewhere.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top