1

Simple question:

Part of my repository looks like this

public class CustomerRepository : IRepository<Customer>
{
   public IQueryable<Customer> GetAll()
   {
     MyDataEntities ent = new MyDataEntities();
     return from c in ent.Customers  select c;
   }
}

Now lets say I have 10,000 customers, and if I do this:

var cus = from c in GetAll() where c.FirstName == "jon" select c;

Please tell me that GetAll() wont load all those 10,000 but lazy load the whole thing? Is it something I need to set somewhere or does it happen automatically?

I wouldn't also know how to check if it is lazy loaded, is there something to see when the actual sql query was spit into sql server?

Sorry about the ignorance.

gideon
  • 19,329
  • 11
  • 72
  • 113

1 Answers1

1

Yes it will. Since your GetAll is returning an IQueryable. One easy way to verify that this is happening is to open up the profiler and look at the query being executed. Or investigate the IQueryable object in the debugger.

Tomas Jansson
  • 22,767
  • 13
  • 83
  • 137
  • Could you elaborate where I could see the profile? Im using sql management studio express 2008 r2 + VS 2010 – gideon Dec 22 '10 at 18:37
  • ok found this but are there newer options : http://stackoverflow.com/questions/760321/is-there-a-sql-server-profiler-for-sql-express – gideon Dec 22 '10 at 18:39
  • 1
    I'm not sure if it is included in the express version. Maybe this one can be used: http://sites.google.com/site/sqlprofiler/. Otherwise you can just use the visual studio debugger and look into the `cus` object and look for the query there. – Tomas Jansson Dec 22 '10 at 18:41
  • Ah didn't think of that ... thanks so much..I think I might try http://code.google.com/p/sqlexpressprofiler/ – gideon Dec 22 '10 at 18:41