I want to make a type request:

var articles = db.Articles.Where(SectionId == 0 ? (не знаю как написать тут чтобы выбралось 10 последних значений) : a => a.SectionId == SectionId); 

Is it possible to use a ternary operation in a query? or make if..else?

  • four
    to construct the structure. To output the last 10 values, you must first call OrderBy, then Take - Veikedo

1 answer 1

 //Я бы делал это как то так, поправьте, если сильно не прав var articles = (SectionId == 0) ? ( from art in db.Acticles select art).OrderBy(art.xxx).Take(10) : ( from art in db.Acticles where art.SectionId == SectionId select art) 
  • one
    orderby can also be specified in the request (inside parentheses, I mean) - Veikedo