silverlight 4.0 - Using Framework Entities, when Include a linked table then Orderby -
i have query made in framework entities uses int id passed in, brings correct question 1 table , brings corresponding answers table using include.
what want happen included answers ordered id's. have searched not found answer works. code below original query works orderby inserted. orderby achieves nothing.
how answers in order in database, id's?
public question getquestionbyid(int id) { question questions; using (var context = new entities()) { questions = context.questions.include("answers").orderby(answer => answer.id).first(question => question.id == id); return questions; } }
you can't (to knowledge)
questions = context.questions.include("answers") .orderby(answer => answer.id) .first(question => question.id == id);
the parameter pass orderby here (answer => answer.id
) misleading: you're ordering questions, not answers. clarify, write this:
objectset<question> questions = context.questions; iqueryable<question> questionswithanswers = questions.include("answers"); iqueryable<question> orderedquestions = questionswithanswers .orderby(question => question.id); question question = orderedquestions.first(question => question.id == id);
in order want, believe can order after query them database:
var question = context.questions.include("answers").first(q => q.id == id); var answers = question.answers.orderby(answer => answer.id);
another possibility might use intermediate anonymous type:
var question = q in context.questions q.id == id select new { question = q, answers = q.answers.orderby(answer => answer.id) }
Comments
Post a Comment