Is there a better way to do this linq sort?
You're correct, it can be costly.

You can just expand the lambda expression:

Assets.OrderBy(a =&gt; {
    var item = a.GalleryItems != null 
               ? a.GalleryItems.FirstOrDefault(gi =&gt; gi.ProductItemCode == productId)
               : null;
    return item != null ? item.SortOrder : 1000;
});


[Quick edit]

The above will work correctly only for LINQ 2 Objects queries.

If you're using EF or any other LINQ database provider, you should leave the query as-is, because it will probably be translated to ISNULL(..., 1000) or something equivalent.