Udostępnij za pośrednictwem


How to see the actual SQL query generated by Entity Framework

It is really simple:

  1: using (TailspinToysEntities context = new TailspinToysEntities())
  2: {
  3:   context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
  4:  
  5:   var products =
  6:       from product in context.Products
  7:       where product.BasePrice > 5.00m
  8:       select product;
  9: }

 

This will show the SQL in the Output -> Debug window.

Comments

  • Anonymous
    June 16, 2014
    Thanks for sharing! Logging should be kept simple like this.

  • Anonymous
    December 08, 2014
    msdn.microsoft.com/en-us/magazine/gg490349.aspx