score:2

Accepted answer

you can use compiled query in other query but you can't make it dependent on the outer query. examples

// you can do 
var someparams = 10;
var dataquery = from x in ctx.somedata
                join y in mycompiledquery.invoke(ctx, someparams) 
                    on x.id equals y.id
                where x.name = "abc"
                select new { x, y };

// you can't do - this example will not compile but let's use it for description
var dataquery = from x in ctx.somedata
                join y in mycompiledquery.invoke(ctx, x.someparams) 
                    on x.id equals y.id
                where x.name = "abc"
                select new { x, y };

the difference is that first example just executes delegate (compiled query is a delegate) and returns iqueryable. the second example can't execute delegate because it is dependent on outer query data so it takes it as something that must be added to expression tree and eveluated during query execution. this fails because ef provider is not able to translate delegate invocation.

score:0

you can combine and embed queries, but i do not think you can use compiled queries. it really shouldn't matter much though, because ef will only compile the combined query once and then cache it (and the database backend should cache the associated query plan).

you could therefore use something along these lines:

var reviewquery = from mcq in reviews
                  select new 
                  {
                      prod_id = mcq.prod_id
                      rating = mcq.review_rating,
                      review = mcq.review_text
                  };

 from cat in ctx.cat_table 
 join prod in ctx.prod_table on cat.category_id equals prod.category_id
 select new
 {
      cat_id = cat.category_id,
      prod_id = prod.product_id,
      name = prod.product_name,
      descript = prod.product_description,
      price = prod.price,
      reviews = from r in reviewquery where r.prod_id == prod_id select r
 }

Related Query

More Query from same tag