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.