Linq To Entity Framework选择整个表

时间:2009-03-04 04:43:19

标签: linq entity-framework

我有以下Linq声明:

(from order in Orders.AsEnumerable()
 join component in Components.AsEnumerable()
    on order.ORDER_ID equals component.ORDER_ID
 join detail in Detailss.AsEnumerable()
    on component.RESULT_ID equals detail.RESULT_ID
 where orderRestrict.ORDER_MNEMONIC == "MyOrderText"
 select new 
            {
                Mnemonic = detail.TEST_MNEMONIC,
                OrderID = component.ORDER_ID,
                SeqNumber = component.SEQ_NUM
            }).ToList()

我希望这会提出以下问题:

select  *   
from    Orders ord (NoLock)   
        join Component comp (NoLock)
          on ord .ORDER_ID = comp.ORDER_ID
        join Details detail (NoLock)
          on comp.RESULT_TEST_NUM = detail .RESULT_TEST_NUM
where   res.ORDER_MNEMONIC = 'MyOrderText'

但我得到3个单独的查询,从表中选择所有行。我猜Linq然后过滤了值,因为我最终得到了正确的值。

问题在于它需要太长时间,因为它会从所有三个表中拉下所有行。

我有什么想法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:4)

从查询中删除.AsEnumerable(),因为它们阻止在服务器上评估整个查询。