I have the following linq statement that is ordering a list of assets by the sort order of a child item:
Assets.OrderBy(a => a.GalleryItems != null &&
a.GalleryItems.FirstOrDefault(gi => gi.ProductItemCode == productId) != null
? a.GalleryItems.FirstOrDefault(gi => gi.ProductItemCode == productId).SortOrder : 1000);
I was wondering if there was a more efficient way to do this as I would have thought having to do 2 a.GalleryItems.FirstOrDefault(gi => gi.ProductItemCode == productId)
would be pretty poor for performance