0

I am trying to get all create, update, delete, and insert statements that my ObjectContext in Entity Framework will execute when I call SaveChanges(). I do NOT want to get these statements during or after execution, such as can be achieved with various profiling methods. I want to get these statements without having to execute them whatsoever. Granted, this would mean some incomplete statements given update behaviors, etc. Also, the ToTraceString() method is not applicable in my case because I do not have direct access to the queries that have been created; I only have access to the ObjectContext. This is, of course, if there isn't a way to get a hold of all previous queries executed on the ObjectContext. My code would look something like this:

public class myContext : ObjectContext
{
    public myContext() { }
    public string GetQueuedSqlStatements()
    {
       //return queuedsqlstatements
    }
}

Does anyone know how to achieve this? From my thin understanding of EF, I imagine that EF does such a thing on the ObjectServices when SaveChanges() is called. I'm not entirely sure how it achieves this - perhaps it loops through the ObjectStateEntries and builds expressions for each ObjectStateEntry then translates them to sql using a provider.

Whatever the case might be, it would be real nice if had access to its 'translate entity to sql statements' functionality.

Thanks for your help.

ylax
  • 376
  • 4
  • 8
  • There was an answer posted a while ago but give it a try: [How do I view the SQL generated by the entity framework?][1] [1]: http://stackoverflow.com/questions/1412863/how-do-i-view-the-sql-generated-by-the-entity-framework – Ric Oct 15 '13 at 20:40
  • Check the source of Entity Framework http://entityframework.codeplex.com. However - why do you need such functiality? It would break the Entity Framework concept which is to support multiple sources (for example a filestream). I am not sure if it would be possible but I hope my post will be helpful. – Pellared Oct 17 '13 at 16:35
  • Thanks Pellard. Wasn't aware it was available. – ylax Oct 29 '13 at 22:10

0 Answers0