2

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.

1
  • 2
    Read (and post) the error messages. In this case the "red squiggle" would have given a good indication of where/what the issue was. (I'm really not sure why this is getting voted up :>) Commented Sep 18, 2013 at 20:59

2 Answers 2

7

You forgot new:

.Select(c => new { c.COURSE_ID, c.COURSE_TITLE })
Sign up to request clarification or add additional context in comments.

1 Comment

That was it! My thanks! I'll mark the answer as soon a the timer is up. I appreciate it!
1

Missing the new keyword:

ddCourse.DataSource = db.COURSE_MASTERs
  .OrderBy(c => c.COURSE_TITLE)
  .Select(c => new {c.COURSE_ID, c.COURSE_TITLE})
  .ToList();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.