Wednesday, 18 September 2013

How can I write this LINQ query as a Lambda expression?

How can I write this LINQ query as a Lambda expression?

Here's my query expression:
ddCourse.DataSource = (from c in db.COURSE_MASTERs
orderby c.COURSE_TITLE
select new { c.COURSE_ID, c.COURSE_TITLE }).ToList();
Just for the sake of knowledge, I'd like to know how to write this as a
Lambda expression. Here is what I have so far:
ddCourse.DataSource = db.COURSE_MASTERs
.OrderBy(c => c.COURSE_TITLE)
.Select(c => {c.COURSE_ID, c.COURSE_TITLE})
.ToList();
Of course, what I have is wrong so I'm hoping that someone can help point
me in the right direction? Again, the only reason I'm doing this is for
the sake of knowledge.

No comments:

Post a Comment