How to view generated SQL from Entity Framework?

Since you don't have Sql Profiler, your best choice would be LINQPad You can use your existing assembly Click Add connection Use a typed data context from your own assembly Entity framework and select your dll You can write queries directly against your model (or copy-paste from your code). Select the SQL tab' under the query window to view the generated SQL code.

Since you don't have Sql Profiler, your best choice would be LINQPad. You can use your existing assembly. Click Add connection -> Use a typed data context from your own assembly -> Entity framework and select your dll.

You can write queries directly against your model (or copy-paste from your code). Select the SQL 'tab' under the query window to view the generated SQL code.

In the context of my question, you have the best solution. It works like a charm. Thanks!

– Alex Oct 28 '10 at 7:09.

Generally, you should always use SQL Profiler to see the SQL statements that being submitted by EF into your database. Also, I think you misunderstood about what StoreGeneratedPattern is. If you look at its possible values inside the model, you'll see that it has identity meaning that the value will be generated (by the database) when the row is inserted and will not otherwise change.

The other options are Computed, which specifies that the value will be generated on inserts and updates, and None, which is the default. So EF will not generate that DateTime field on the fly for you, you need to manually create it and then update your model from database so that EF will generate appropriate metadata to work with it at runtime.

I don't have the profiler installed, and I don't see it as a feature I can add when re-running the setup, so sadly, that's a dead end. As far as StoreGeneratedPatern, I'm pretty sure I understood it correctly when I read up on it at MSDN. Unless Identity is intended only for PK columns and nothing else?

– Alex Oct 28 '10 at 3:11 Either way, how do I overcome the issue of EF blocking database generated values? – Alex Oct 28 '10 at 3:11 Ok, first you need to tell me about your approach: Do you have an existing database and creating a model based on it or you are following a model-first approach? – Morteza Manavi Oct 28 '10 at 3:18 I have an existing database and I'm creating the model off of it.

– Alex Oct 28 '10 at 4:31.

You can use the Entity Framework Profiler (EFProf). It's not free, but there's a 30-day trial available. It does a lot more neat stuff besides showing you the SQL statements.

– Kristof Claes Nov 23 '10 at 14:17 It's a handy tool, except you have to actually modify your code and add a reference for the tool to work well. – Chris Jul 1 at 20:30.

The free AnjLab Sql Profiler will work if real SQL Profiler is not available because you're using SQL Server Express: anjlab.com/en/projects/opensource/sqlpro.... It's not quite as nice as the real thing but it gets the job done well enough.

One solution would be to capture the network traffic and have a look at the data on that level. Microsoft Network Monitor does a good job of this. Of course, that only works if you're using a separate DB server, and the connection is not encrypted.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions