Linq to Entity, query sql

D

Davide Lo giudice

I'm using C#, Linq to Entity and Sql Server 2005 Express.

I need to see the queries created by linq. What do I have to use?

Thaks.
sorry, but I'm a new VS developer. I have developed with delphi all my live.
Davide
 
M

Marc Gravell

I need to see the queries created by linq. What do I have to use?

To repost something from a few days ago (look for ****), see below.
There is also a drop-in visualizer dll you can add to VS pro to see
the command from a query by hovering on the query in a breakpoint, but
last time I checked this was unsupported.

Marc

using (pubsDataContext dc = new pubsDataContext())
{
var query = dc.authors.StartsWith("au_lname", "b")
.OrderBy(x => x.au_lname).ThenBy(x => x.au_fname)
.Select(x => new { Forename = x.au_fname, Surname
= x.au_lname });
// **** THIS BIT ****
Console.WriteLine(dc.GetCommand(query).CommandText);
// SQL
foreach (var auth in query) // Results
{
Console.WriteLine("{1}, {0}", auth.Forename,
auth.Surname);
}
}
 
M

Marc Gravell

Ahh, sorry, that was LINQ-to-SQL; but I think there is a similar plug
in LINQ-to-entity.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top