Alan2
Alan2

Reputation: 24582

How can I order data returned in an anonymous type?

I have this code:

         return Ok(new
            {
                Answer = (string) null,
                Text = question.Text,
                Answers = question.Answers.Select((a, i) => new
                {
                    AnswerId = a.AnswerId,
                    AnswerUId = i + 1,
                    Correct = (bool?) null,
                    Response = (bool?) null,
                    Text = a.Text
                })
            });

How can I order the Answers returned by AnswerId ?

Upvotes: 1

Views: 40

Answers (1)

Jonathan Allen
Jonathan Allen

Reputation: 70327

Just add

.OrderBy( z => z.AnswerId)

immediately after your Select statement.

Upvotes: 3

Related Questions