newbie question: how to view the SQL conversion.


I am a LinqPad 5 newbie. I'm trying to write a lambda linq query in C# and I'm not sure how to see the conversion to SQL.

I have successfully connected to a database, referenced my dlls, and configured the app.config file properly (at least I'm not getting any errors).

So I'm trying the following script:

ACM.RiskAlive.Core.Services.CompanyService cs = new ACM.RiskAlive.Core.Services.CompanyService(new ACM.RiskAlive.Core.Data.RiskAliveEntities());

var x = cs.GetOperatorCompanies().Where(c => c.CompanyId == 3);

GetOperatorCompanies() returns IQueryable.

But when I run this script, I get no output.

There must be some way of telling LinqPad that I want to see x being converted to SQL (or the expression cs.GetOperatorCompanies().Where(c => c.CompanyId == 3)).

Please help.


  • edited July 2016
    You won't get any output when using C# Statements mode or C# Program mode, unless you call Dump() on an object.

    i.e. try changing your code to:
    var x = cs.GetOperatorCompanies().Where(c => c.CompanyId == 3).Dump();

    then you will see the SQL that was executed in the SQL tab in the results pane.

    Until you iterate over an IQueryable, whether by using a for loop, a ToList() or Dump(), it doesn't execute any SQL and you won't see anything in this tab. This is because they use what is called lazy evaluation.
  • Thanks kingkeith.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!