Question

As it's (at this moment) impossibe to use Include() in a compiled query, I'm trying to rewrite them to joins. But it doesn't seem to work out quite as I would want it to.

Say I have this relation:

Order              OrderState
Id                 Id   
OrderStateId       Description

Now I used to fetch the description as follows:

var q = (from o in context.Orders
         where o.Id = orderId
         select o).Include("OrderState");

I've tried rewriting this as:

var q = (from o in context.Orders
         join st in context.OrderStates on o.OrderStateId equals st.Id
         where o.Id = orderId
         select o);

But the OrderState is still null in my resultset. How would I go about fixing this (in a way that;s acceptable for compiled query)?

Was it helpful?

Solution

If you can't use .Include, you need to actually include o.OrderState somewhere in the result, so how about this?

var q = (from o in context.Orders
         where o.Id = orderId
         select new { Order = o, o.OrderState });

o.Order.OrderState should get hooked up to o.OrderState without extra help for each result in q.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top