How to rewrite this LINQ using join with lambda expressions?

Most LINQ seems to be written with lambda expressions. How can I rewrite this linq using lambda, a kind of confusion with style (especially with bundles)?

var responses = from c in questionRepository.GetReponses() join o in questionRepository.GetQuestions() on c.QuestionID equals o.QuestionID where c.UserID == 9999 orderby o.DisplayOrder select new { o.QuestionText, c.AnswerValue }; 
+7
source share
2 answers

I prefer the LINQ syntax for Joins, as I think it looks cleaner.

Anyway, here's how to translate LINQ-join to "Lambda Expression" -join.

Translation for:

 from a in AA join b in BB on aY equals bY select new {a, b} 

There is:

 AA.Join( // L BB, // R a => aY, b => bY // L -> join value, R -> join value (a, b) => new {a, b}) // L+R result 

Other LINQ keywords are much easier to convert (like OrderBy(u => u.DisplayOrder) and just โ€œconnected togetherโ€ with . ) - let it go!

+15
source
 var responses = questionRepository.GetReponses() .Join(questionRepository.GetQuestions(), c => c.QuestionID o => o.QuestionID (c, o) => new {c, o}) .Where(x => xcUserID == 99999) .OrderBy(x => xoDisplayOrder) .Select(x => new {xoQuestionText, xcAnswerValue}); 
+6
source

All Articles