Linked Questions
131 questions linked to/from How do I view the SQL generated by the Entity Framework?
69 votes
8 answers
102k views
Log Queries executed by Entity Framework DbContext [duplicate]
I'm using EF 6.0 with LINQ in MVC 5 project. I want to log all the SQL queries executed by the Entity Framework DbContext for debugging/performance-measurement purpose. In Java/Hibernate, equivalent ...
30 votes
3 answers
49k views
How to get the sql generated by the entity framework [duplicate]
How can I get the sql script generated by an entity framework query? i.e. If I write entityDataDontext.table1.Where(r => r.primarykey == 1).First(); then how can I get the SQL which should be ...
2 votes
1 answer
335 views
Is it possible to access the generated SQL with Linq To Entities [duplicate]
I know you can access the raw SQL generated by Linq To Sql, but is it possible to use Linq To Entities to build a query and then access to generated SQL? The reason I need to do this is because I ...
-1 votes
1 answer
238 views
How to see the SQL comand when I use Entity Framework [duplicate]
I would like to know how I could see the SQL command when I use the saveChanges method in Entity Framework. I am using EF 4.4. Thanks.
221 votes
10 answers
222k views
Get SQL code from an Entity Framework Core IQueryable<T>
I am using Entity Framework Core and I need to see which SQL code is being generated. In previous versions of Entity Framework I could use the following: string sql = ((System.Data.Objects....
105 votes
10 answers
369k views
instance of entity type cannot be tracked because another instance with same key value is tracked [closed]
I'm using generic repository pattern in asp.net core 2.0 which can not dispose repository object, when I am going to update the entry its updated for one time successfully but when I am trying to ...
92 votes
8 answers
92k views
How can I log the generated SQL from DbContext.SaveChanges() in my Program? [duplicate]
According this thread, we can log the generated SQL via EF, but what about DbContext.SaveChanges()? Is there any easy way to do this job without any extra frameworks?
78 votes
9 answers
107k views
How to view LINQ Generated SQL statements?
How is it done using the ObjectQuery method?
49 votes
5 answers
46k views
OriginalValues cannot be used for entities in the Added state [duplicate]
I am using Entity Framework to build an web application, the database is created on startup and my seed method adds some entities to the database without any problem. Also the retrieve of the entities ...
58 votes
4 answers
131k views
Get SQL query from LINQ to SQL?
I have a query which I am passing byte[] as a parameter. I am trying to get the SQL query out of it and run that query in management studio to debug. How can I extract the SQL statement from it? ...
25 votes
5 answers
41k views
Optimize entity framework query
I'm trying to make a stackoverflow clone in my own time to learn EF6 and MVC5, i'm currently using OWin for authentication. Everything works fine when i have like 50-60 questions, i used Red Gate ...
18 votes
5 answers
8k views
EF Query using .Contains() and .ToLowerInvariant() Results in no matches when match is found at the end of a string
Is it possible to step into a linq query? I have a linq to entity framework 4 query in it's simplest form: List = List.Where(f => f.Value.ToString().ToLowerInvariant().Contains(filter....
20 votes
5 answers
4k views
Performance for using 2 where clauses in LINQ
In LINQ-to-Entities you can query entities by doing: var students = SchoolContext.Students.Where(s => s.Name == "Foo" && s.Id == 1); I know that behind the scenes it will be translated to ...
12 votes
3 answers
20k views
Entity Framework LINQ contains not case insensitive
I'm having some 'tear my hair out'-problem with Entity Framework and I just can't find a solution. What I want to do is compare strings for a search function I'm running on the server. It's basically:...