【问题标题】:Linq To Entity Framework selecting whole tablesLinq To Entity Framework 选择整个表
【发布时间】:2009-03-04 04:43:19
【问题描述】:

我有以下 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 正在过滤这些值,因为我最终得到了正确的值。

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

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

【问题讨论】:

    标签: linq entity-framework


    【解决方案1】:

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

    【讨论】:

    • 你摇滚!!!非常感谢你的回答。我明天要做一个演示,我想在演示中使用它。现在我可以了!!再次感谢您!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多