Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

I am Jalpesh Vadgama a Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 6 years of experience in .NET Technology.
Browse by Tags · View All
#ASP.NET 88
#DOTNET 87
BRH 79
ASP.NET 72
#.NET 52
C#.NET 48
DOTNET 47
ASP.NET 4.0 31
ASP.NET MVC 29
VisualStudio 27

Archive · View All
December 2010 16
July 2011 13
April 2011 13
April 2012 12
January 2011 12
June 2011 11
May 2011 11
May 2012 8
February 2013 7
January 2013 7

Where I can find SQL Generated by Entity framework?

Dec 19 2012 1:50PM by Jalpesh   

Few days back I was optimizing the performance with Entity framework and Linq queries and I was using LinqPad and looking SQL generated by the Linq or entity framework queries. After some point of time I got the same question in mind that how I can find the SQL Statement generated by Entity framework?.

After some struggling I have managed to found the way of finding SQL Statement so I thought it would be a great idea to write a post about  same and share my knowledge about that. So in this post I will explain how to find SQL statements generated Entity framework queries.

To demonstrate the idea Let’s a very simple console application with C# and then  create a table called ‘Customer’ with CustomerId and CustomerName field in sql server.

SQL Generated by Entity framework

Now once our table is ready it’s time to create a Entity framework model.

How to Find SQL Generated by Entity Framework - Entity Framework Model

Now once Model is ready It’s time to write a simple query in console application where we want to get all customer name like following.

using System;
using System.Runtime.CompilerServices;
using System.Linq;
using System.Data;

namespace EntityframeworkSQL
{
    class Program
    {
        static void Main(string[] args)
        {

            using (CustomerEntities customerEntities = new CustomerEntities())
            {
                var customerNames = from c in customerEntities.Customers
                             select c.CustomerName;
                string sql = ((System.Data.Objects.ObjectQuery)customerNames).ToTraceString();

                Console.WriteLine(sql);

            }
            
        }
    }
}

So here in the above code for that. here I have created a object of my customer entity with help of using and then written a simple query to get all the customer name. Now with the help of System.Data.Objects.ObjectQuery class ToTraceString method I am able to find the SQL Generated by the statement. Here I have direct cast customerNames to ObjectQuery class and find sql generated by statement via ToTraceString method.

Now let’s run this console application via pressing F5 and following is a output as expected.

EntityFrameworkSQLQuery

As you can see the SQL statement generated by entity framework. Hope you like it. Stat tuned for more.

Shout it

Tags: dotnet,entity framework


Jalpesh
15 · 11% · 3548
2
 
0
Lifesaver
 
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • You can also use LINQpad

    commented on Dec 19 2012 10:37PM
    Marc Jellinek
    95 · 2% · 586

Your Comment


Sign Up or Login to post a comment.

"Where I can find SQL Generated by Entity framework?" rated 5 out of 5 by 2 readers
Where I can find SQL Generated by Entity framework? , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]