Querying Data Becomes Slow in EF 4.1 RRS feed

  • Question

  • Hi all,

    I'm using a simple linq to entities and DbContext to query some data. What I noticed is that querying becomes slower and slower and eventually very slow, here's the method I'm using:


    public static IList<BatchReceivedFilter(this IQueryable<BatchReceivedbatchesstring namestring invoiceNumber)


                var result = batches

                    .Where(b => string.IsNullOrEmpty(name) || b.Groups.Any( => g.Product.Name.Contains(name))

                    .Where(b => string.IsNullOrEmpty(invoiceNumber) || b.InvoiceNumber.Contains(invoiceNumber));

                return result.ToList();



    I wrote the method this way just for convenient usage like this: Context.ReceivedBatches.Filter("name", "incoiceNumber");


    so, any ideas?


    Thank you


    Clarity VS Precision
    Friday, December 9, 2011 2:36 PM

All replies

  • Hi Giorgi,

    Welcome to MSDN Forum!

    I suggest you to use SQL Profiler to check the T-SQL which your query statement auto-generated, to make sure the whether the T-SQL is what you want. EF and Linq alway generate T-SQL which is easy to generate, so it may not as same as you want. You can also track the time that every course cost. In my opinion, the 'Any' query may take a plenty of time.

    Here's a link which introduce the performance cosideration of Entity Framework, you can refer to it.

    Performance Consideration( Entity Framework)

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Monday, December 12, 2011 8:11 AM