Load an entity with its navigation properties sorted

Oct 28, 2013 at 10:00 PM
Hi everybody,

I am having a "Patient" entity, which has detail items related to it, like "Diagnosis", "Therapy", "Evaluation", "FollowUp" etc, each having a corresponding DiagnosisList, TherapyList, EvaluationList and so on navigation properties Lists on the root Patient entity.
When I load a specific patient with
var _patient = context.Patient.Where(c => c.ID == this.ID).FirstOrDefault();
I also get all the navigation properties. However, these properties are not sorted in any way.

My question is how do I sort them? Efforts like
_patient.DiagnosisList.OrderBy(n => n.DiagnosisDate);
do not seem to work.

All the best,
Nov 7, 2013 at 11:46 AM
This is really an Entity Framework question. The code output is just EF really. That said all LINQ methods will work fine. If you want a list then this shoudl work.

var list = _patient.DiagnosisList.OrderBy(n => n.DiagnosisDate).ToList();

If this does not work, what error are you getting? All "List" objects are just IEnumerable collections. I do not know why your LINQ statements do not work without some sort of error message.