Does whole rows come into memory at that time when GetTable method of DataContext is called ? RRS feed

  • Question

  • Hello,

     public static IEnumerable<Product> GetProducts()
                DataContext dc = new DataContext(Properties.Settings.Default.AdventureWorksConnectionString);
                return dc.GetTable<Product>();

    and then i am using that function in this LINQ query .

     var products = GetProducts().Where(prod => prod.ProductID == 4);       
    Now my query is that when calling this GetProduct  method whether whole rows at a time will get returned or only filtered data according to the filter criteria will come to memory ? I am worrying if that table contains thousands of records that will there be any performance issue ?
    Tuesday, May 1, 2012 5:56 AM


  • Hi bootstrap2,

    Welcome to MSDN Forum.

    Yes, you are correct, if you call foreach loop or some method likes "ToList()" to execute the query statement, all the records will be queried out into memory and then do filtering in the memory. You can use SQL Profiler to find the exact T-SQL which the query generated. The generated T-SQL will not contains the where statement.

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Shyam Kr Thursday, May 3, 2012 3:52 PM
    Wednesday, May 2, 2012 5:27 AM