Entity Framework CTP5 is being used by me in "code only" mode. I'm using a LINQ query on an object that the database returned since the query is moving so slowly. Is there a way for me to get the SQL statement that the query generates?
Topic currentTopic = (from x in Repository.Topics let isCurrent = (x.StoppedAt <= x.StartedAt || (x.StartedAt >= currentTopicsStartedAtOrAfter)) where x.Meeting.Manager.User.Id == user.Id && isCurrent orderby x.StartedAt descending select x).FirstOrDefault();
A ancestor of DbContext is the "Repository" attribute.
It's a bit complex since I'm explicitly defining the logic in the query because EF can't utilize my helper methods on the objects.
Is there a way for me to export the SQL that this LINQ query will generate and save it somewhere else, like my Log4net repository?
Either utilize the Event Tracing for Windows (SQL Profiling) functionality from Performance Profiler for ANTS or SQL Trace to directly capture the query that is now executing on the server.
Your further options are:
Additionally, you may utilize common EF.
like @Andy recommended, but
This technique is absent from CodeFirst (or I couldn't locate it).
because the time is promptly put into action