Its possible to generate SQL scripts from EntityFramework queries? - entity-framework

Whenever I make a query with Entity in debug mode, it's possible to see the SQL script that creates, there's any way to get them without actually debug each request at the time?

Related

Graphical query designer for PostgreSQL

I have for years used MS Access and its query tool that is used for making queries. This tool is so good that I have never been forced to do very much SQL programming myself. The query tool has done all the work.
However, now I have started using Postgres and the Graphical Query Builder in pgAdmin. It seems that the Graphical Query Builder is rather primitive: It cannot be used if you need an aggregate function like SUM or COUNT.
Is this really correct?
Does anybody know a better graphical query builder for PostgreSQL?
Until now I have 'solved' the problem by linking MS Access to the Postgres database through ODBC and used MS Access' query tool to generate SQL commands which I then copy into pgAdmin's Graphical Query Builder - and edit the SQL commands until everything is correct.
SQL Maestro has a query designer, although it is PC only, AFAIK
http://www.sqlmaestro.com/products/postgresql/maestro/screenshots/getting_started/visual_query_builder/
EMS SQL Manager also has a query designer
http://www.sqlmanager.net/en/products/postgresql/manager/screenshots
Try SQLeo, its free and has a specific feature (autosavepoint) to prevent
ERROR: current transaction is aborted, commands ignored until end of transaction block.
Try a browser-based query builder for PostgreSQL called Skyvia. And you don’t have to worry about which operating system it works. It works where a browser exists. Simply make a connection to your PostgreSQL database and start building your queries. See a sample below.
Note that you can still switch between SQL code and query builder if you want to, just like in MS Access. Get the details here.

How to generate SQL script from code first seeding?

As I am unable to use the migrate.exe tool to update the database, I am creating migration SQL scripts, and applying them manually, which works perfectly.
As the seed part is not included into the migrations, they do not yield an SQL script.
How could I get the seed method to generate the SQL script?
I am currently applying the seed method to my local DB. One way to solve the problem would be to intercept the SQL calls with the entity framework interceptor, but that sound like a dirty hack. So is there a better way to do it?

How to find Who did some query on the database and when?

I have a SQL Server 2008 R2 with a database in it.
How to find a certain query that was executed and from what IP ?
I have tried to go through the transaction logs but I cant understand nothing there.
You should use SQL Server Profiler. It's usually installed by default - look in the SQL Server folder on the Start Menu. When you open it, start a new trace and select the database. In the Trace Properties dialog choose the TSQL template. This will then record all the queries running on the database, along with a whole lot of other stuff. It's not massively easy to track stuff down in here, but look for the BatchStarting events to find the SQL that gets run. Then you should run the procedure sp_who2 on the database so you can match up SPIDs in the profiler to logins.

Batching ExecuteSqlCommand statements on a code-first DbContext

I'm calling ExecuteSqlCommand several thousands times per minute and each one is a round-trip to the database. The command itself calls a stored procedure and the parameters vary from INTs to NVARCHARS to "Structured" table-value parameters. When I look at the SQL commands generated by Entity Framework via SQL Profiler quite a sizeable chunk of data is being sent to the DB.
Given that there is no return value from the SP, it's very much "fire and forget", I'd like to try to batch up the SQL commands and send, say, a batch of 10 at once. Is this possible using Entity Framework? Is there a way to get Entity Framework to return me the full SQL command per call and then I could concatenate the SQL myself and call ExecuteSqlCommand myself?
EntityFramework currently does not support batching. However if you are just executing SQL queries then I don't see a benefit of using EntityFramework. You can go one level below to pure ADO.NET where it is supported to send Sql commands in batches. Take a look at this MSDN post for more details: http://msdn.microsoft.com/en-us/library/aadf8fk2.aspx

How to enter SQL log in ADO.NET Entity Framework

I'm using ADO.NET Entity Framework for our business application in ASP.NET website. We're using WCF and LINQ to query the data source. My problem is that data loading from database (for e.g. to load data in gridview) is taking much more time than expected, so we want to log statements in ado.net generated sql statement so we can see which query is taking more time .
How to do this?
I would strongly suggest that you use SQL Profiler rather than creating your own logging mechanisms.
Microsoft SQL Server Profiler is a graphical user interface to SQL
Trace for monitoring an instance of the Database Engine or Analysis
Services. You can capture and save data about each event to a file or
table to analyze later. For example, you can monitor a production
environment to see which stored procedures are affecting performance
by executing too slowly.
In your C# application, in your ConnectionString, add Application Name=yourApp. This will make it easier to locate in SQL Profiler.