Question

I have the following Linq statement:

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

I expect this to put out the following query:

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'

but instead I get 3 seperate queries that select all rows from the tables. I am guessing that Linq is then filtering the values because I do get the correct values in the end.

The problem is that it takes WAY WAY too long because it is pulling down all the rows from all three tables.

Any ideas how I can fix that?

Was it helpful?

Solution

Remove the .AsEnumerable()s from the query as these are preventing the entire query being evaluated on the server.

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