Firstly, I would recommend that you either do it in pure SQL as a function or a stored procedure, and then access it via linq or add a price column to the product table. It looks like the price will be a normal attribute to add to all your products, even if that price is NULL.
SQL:
select p.* from products p left outer join productspecs ps on p.id = ps.product_id and ps.spec_name = 'Price' order by ps.spec_value
Having said that, here is the weird LINQ bit that should work on your table (I may have invalid column names):
var products = from p in db.Products join ps in (from pss in db.ProductSpecs where pss.spec_name== "Price" select pss ) on p.id equals ps.product_id into temp from t in temp.DefaultIfEmpty() orderby t.spec_value select p;
I tested this on some tables, as described above, and created 5 products, three with prices in different order of values, and this LINQ ordered them the same as SQL above, and also returned zero rows of results.
Hope it works!
source share