How do I see what SQL Enttity Framework SaveChages is generating?
There often are times when I would like to see what SQL is being generated by EF. For instance I query an object, modify it and save it back:
var context = new EntityModel();
var MyObj = context.FooTable.First(o => o.id = SearchId);
MyObj.Property = SomeValue;
context.SaveChanges();
I get some silly error that I may be ab开发者_运维百科le to troubleshoot if I could see the SQL. I am far from a EF expert and it would help me learn too.
Update: I think what I really want to know is: In auto-tracking EF objects as shown above, how do I get at the ObjectContext/ObjectQuery to use ToTraceString() to see what was executed in SaveChanges()?
I use the free SQL Express Profiler
It sounds like pretty easy task but it is not because ADO.NET team somehow forgot to include such basich functionality. Check EF Tracing provider. That is something which can help you log SQL commands. Otherwise go with SQL Profiler and learn how to use filters when establishing new trace.
the EF Profiler is a great tool for this - its not free though :(
精彩评论