score:0
You can use ToTraceString()
:
ObjectQuery<SomeTable> query = (from x in Entities.SomeTable select x).Count();
Console.WriteLine(query.ToTraceString());
score:0
You can use the Database.Log
to log any query made like this :
using (var context = new MyContext())
{
context.Database.Log = Console.Write;
// Your code here...
}
Usually, in my context's constructor, I set that to my logger (whether it is NLog, Log4Net, or the stock .net loggers) and not the console, but actual logging tool is irrelevant.
score:0
In EF6 and above, you can use the following before your query:
context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
I've found this to be quicker than pulling up SQL Profiler and running a trace. Also, this post talks more about this topic: How do I view the SQL generated by the Entity Framework?
Source: stackoverflow.com
Related Articles
- How to look at sql generated by EntityFramework when Count is used
- prevent unnecessary cross joins in count query of generated sql code
- What would this sql query (w count and group by) look like when translated to linq?
- Entity-framework code is slow when using Include() many times
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- Why does LINQ query throw an exception when I attempt to get a count of a type
- Is C# LINQ OrderBy threadsafe when used with ConcurrentDictionary<Tkey, TValue>?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Does ascending keyword exist purely for clarity when used with orderby?
- How to reuse a linq expression for 'Where' when using multiple source tables
- Linq Select Statement slow when getting COUNT
- Avoiding code repetition when using LINQ
- How to get total results count before .Take() - but when using .Take()
- Return Count from Netflix oData Service When the LINQ Count() Method Doesn't Work
- Forcing Entity Framework to not generate NCLOB's when building Linq-to-Sql Code (Model First)
- LINQ Source Code Available
- Trace LINQ when Joins are used
- .NET 4 Code Contracts: "requires unproven: source != null"
- Removing a single item from an enumerable source when the items are equal
- How to construct IQueryable query using Linq when I just need count without reading all documents in Document-Db database?
- Compilation error when i used lambda creator with base type for `Where` condition in linq
- CreateDocumentQuery throws exception when used with LINQ, fine with SQL
- When Where clause is used inside Linq statement produces different results than when used outside
- Why does using LINQ change properties when used in if
- Enforce ordering of OData items even when $top is used
- LINQ query returns old results when source list is re-initialized
- Is a statement recalculated in every iteration when used in LINQ?
- 'The LINQ expression node type 'Invoke' is not supported in LINQ to Entities' when lambda is passed as a parameter, but not when used directly
- Breaking a loop using TakeWhile when a count or length condition is meet
- How to Count items in nested collection / codefirst EntityFramework
- LINQ: Converting grouped list into new list
- "Value cannot be null" while creating an XElement from the attributes where one or more value is null
- DataGridView & Linq
- Write from/group in method instead of query syntax in efcore
- OrderBy ThenBy - Easiest way to catch remaining (equal) items?
- Cannot Implicitly convert anonymoustype#1 to Object
- How to filter an xml list based on whether it has a particular attribute
- How to pass value for DbPropertyEntry?
- linqtosql maintain ordering of list
- Primitive type error in LINQ to SQL query+subquery
- How to understand this lambda expression?
- HTMLAgilityPack node name filter doesn't work
- Lambda Expression of Select * from TableName
- Type Inference failed in a call to 'join' on nullable and non-nullable int
- Convert T-SQL to LINQ using the WHERE IN clause with a Nested Subquery
- How to prevent a condition from being repeated in several navigation properties in lambda expressions or linq
- Convert SQL sub query to LINQ in C#
- Linq dynamic orderby not working
- Filtering in Linq in MVC4
- Enumerating stored procedure result - The result of a query cannot be enumerated more than once