문제

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)?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top