C # How to use OrderBy with a property in a nested class?

I have a collection of IEnumerable classes that I want to sort. One of the properties I want to sort is a nested class. What is the syntax to make this work? The code below shows what I am trying to do, although it does not work.

AbsenceViewModel avm = new AbsenceViewModel(); if (sort.Column != null) { if (sort.Column == "OtherLeaveName") avm.ListNames = avm.ListNames .OrderBy("NestedClass.Name", sort.Direction); else avm.ListNames = avm.ListNames (sort.Column, sort.Direction); } 

Thus, setting "NestedClass.Name" does not work. What do i need to do instead?

+4
source share
1 answer
 avm.ListNames.OrderBy(x => x.NestedClass.Name) 
+4
source

All Articles