I like the Lambda syntax, so I came up with this equivalent. I see how query syntax is cleaner for joins.
var orderedOptions = options_list .Join( types_list, option => option.Type_ID, type => type.ID, (option, type) => new { Option = option, Type = type }) .OrderBy(x => x.Type.Ordering) .Select(x => x.Option);
For a small reduction (which I'm not sure), this creates a new object with only the Ordering property, and not for the entire Type class. There is not much here, but I had a large class with sorting data, and I only need the sorting property. I donβt know if it was important, but it was easier to read.
var orderedOptions = options_list .Join( types_list, option => option.Type_ID, type => type.ID, (option, type) => new { Option = option, Ordering = type.Ordering }) .OrderBy(x => x.Ordering) .Select(x => x.Option);
It looks like the query syntax allows you to order in the original request, and the lambda requires ordering after the connection creates a new object. Perhaps they really do the same under covers: creating a merged object that will be sorted, then selected.
goodeye Nov 28 '12 at 0:10 2012-11-28 00:10
source share