C# How to use OrderBy with a property on a nested class?
I have a IEnumerable collection of a class which I want to sort. One of the 开发者_高级运维properties I want to sort is in 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);
}
So putting in "NestedClass.Name" doesn't work. What do I need to do instead?
avm.ListNames.OrderBy(x => x.NestedClass.Name)
精彩评论