[c#] LINQ [大文字]の大文字小文字を選択


Answers

これがあなたを助けるかもしれない

var query = from grade in sc.StudentGrade
                        join student in sc.Person on grade.Person.PersonID
                                      equals student.PersonID
                        select new
                        {
                            FirstName = student.FirstName,
                            LastName = student.LastName,
                            Grade = grade.Grade.Value >= 4 ? "A" :
                                        grade.Grade.Value >= 3 ? "B" :
                                        grade.Grade.Value >= 2 ? "C" :
                                        grade.Grade.Value != null ? "D" : "-"
                        }; 
Question

この質問には既に回答があります:

これをLINQにどのように変換できますか?

select t.age as AgeRange, count(*) as Users
from (
  select case  
    when age between 0 and 9 then ' 0-25'
    when age between 10 and 14 then '26-40'
    when age between 20 and 49 then '60-100'
    else '50+' end as age
  from user) t
group by t.age

ありがとうございました!




このようなもの?

var users = (from u in Users
             select new
             {
                User = u,
                AgeRange =
                    u.Age >= 0 && u.Age <= 9 ? "0-25"  :
                    u.Age <= 14              ? "26-50" :
                    u.Age <= 49              ? "60-100":
                                               "50+"
              }).GroupBy(e => e.AgeRange);



Links