t-sqlentity-framework-5asenumerable

how can I know what T-SQ is executed?


I have this:

List<Personal> lstPersonal = dbContext.Personal.Select(x => new
                    {
                        IDPersonal = x.IDPersonal,
                        Nombre = x.Nombre
                    }).AsEnumerable().Select(x => new Personal
                    {
                        IDPersonal = x.IDPersonal,
                        Nombre = x.Nombre
                    }).ToList();

I would like how can I know the T-SQL that is send to the database. I know that if I use an IQueriable I can use ToString for example to know the querty, but in this case I don't know hoe to do it.

The purpose of this query is to get onle a few fields of the database, it works, but I would like to know if all the fields are get from the database and later select only the desired fields or the database is send only the desired fields.

Thanks.


Solution

  • You can view the queries run against your server using the SQL Server Profiler.

    It is shipped with the SQL Server Management Studio, from where you can start it going to the menu Tools and then select SQL Server Profiler; of course it can also be started independently. (But who does that? :D)