views:

132

answers:

1

Hi community,

I'm interessted, how does Linq2Sql handles a compiled query, that returns IQueryable.

If I call an extension method based on a compiled query like "GetEntitiesCompiled().Count()" or "GetEntitiesCompiled().Take(x)". What does Linq2Sql do in the background? This would be very bad, so in this situation I should write a compiled query like "CountEntitiesCompiled".

Does he load the result (in this case "GetEntitiesCompiled()") into the memory (mapped to the entity class like "ToList()")?

So what situations make sense, when the compiled queries return IQueryable, that query is not able to modify, before request to the Sql-Server. So in my opinion I can just as good return List.

Thanks for answers!

A: 

As I understand it - if it can't use the pre-compiled query exactly (because you have composed it further), it just runs it as it would any regular IQueryable query - so it will indeed still issue a SELECT COUNT(1) FROM ... (it shouldn't iterate the entire table / whatever).

But the real answer is: profile it; you can hook .Log to see the TSQL, for example:

myDataContext.Log = Console.Out; // write TSQL to the console

or just use SQL trace to see what goes up and down the wire.

Marc Gravell
The DataContext.Log and Sql-Profiler shows me the full select statement from the compiled query without the changes from the extension method like "Count()" or "Take(x)"....So the result does mapped to the entity classes. This is a very overhead for an operation like "Count()".
Beni
Is my presumption correct?
Beni