Question

How can I get the sql query generated by the Context.SaveChanges(); command. I need this because, the user will have the option to create a script for data distribution, instead of inserting in the local base.

Thanks.

UPDATE:

I'm using entity framework with WCF Data Services.

Was it helpful?

Solution 2

My solution is: Do not use Wcf Data Services which is still incomplete, if you need security and reliability, use Wcf Services, so you can have entity framework in its own extent. Wcf data services is not mature enough.

For the scripts, iam using string concatenation with stringbuilder.

OTHER TIPS

If you are using EF6, you can use DbContext.Database.Log. For instance, using the following, the SQL will be outputted to the console along some performance data:

Context.Database.Log = Console.WriteLine;

You may also perform interception in case you want to stop DbContext.SaveChanges from actually saving the changes.

You can find information about both logging and interception in this MSDN article.

In case you are using previous versions, may check out either this or this article.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top