View Raw SQL in EF Core – Simple Option

Hi everyone,

I’ve been looking for a simple way of viewing the raw output of sql in my local environment without having to make code changes and came across the following config setup:

{
“Logging”: {
“LogLevel”: {
“Default”: “Debug”,
“System”: “Information”,
“Microsoft”: “Information”
}
}

This will show the sql statements in your output window without requiring any additional code:
sql-output

Thanks to this stackoverflow post for the answer: https://stackoverflow.com/a/54704006/522859

Exit Raspberry Pi Camera Preview

Hey everyone,

I ran into a bit of a weird issue with a raspberry pi camera preview today. After starting the preview I hit an uncaught exception which meant that exitPreview was never called.

To get around this use the terminal hotkey and kill the python process. Note that while you won’t be able to see the terminal, it will be running in the background.

https://www.raspberrypi.org/forums/viewtopic.php?t=152239&p=998212
ctrl + alt + t
pkill python
pkill python3

Unescape String in Watch Window – Visual Studio

Hey everyone,

Just a quick post on how to remove the escape characters from a string in the watch window. All you’ve got to do is append “,nq” (short for no quotes) to the watch variable name.

MyLongString becomes MyLongString,nq

This removes all of the quotes and line breaks. Pretty handy for when you’ve got to copy the values.

Check out these links for more info:

MSDN: http://msdn.microsoft.com/en-us/library/e514eeby%28v=vs.100%29.aspx
StackOverflow: http://stackoverflow.com/a/9786653/522859

View Generated SQL in Entity Framework (EF)

Hey everyone,

Just a quick post on how to view the generated sql in entity framework. To start with, just add the following line to your db context constructor:

public class TestDbContext : DbContext
    {
        public TestDbContext() : base("name=TestDbContext")
        {
            this.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); //This line
        }
        ...

With this line added, you should now be able to see all of your generated sql in the output window.

SELECT TOP (1) 
    [Project1].[VidId] AS [VidId], 
    [Project1].[CreatedAt] AS [CreatedAt], 
    [Project1].[Check] AS [Check], 
    [Project1].[SourceCheck] AS [SourceCheck]
    FROM ( SELECT 
        [Extent1].[VidId] AS [VidId], 
        [Extent1].[CreatedAt] AS [CreatedAt], 
        [Extent1].[Check] AS [Check], 
        [Extent1].[SourceCheck] AS [SourceCheck]
        FROM [dbo].[Vids] AS [Extent1]
        WHERE [Extent1].[VidId] < @p__linq__0
    )  AS [Project1]
    ORDER BY [Project1].[VidId] DESC

-- p__linq__0: '535' (Type = Int32)
-- Executing at 28/06/2014 5:00:16 PM +10:00
-- Completed in 0 ms with result: SqlDataReader

If you’re not using EF6, there were a few other options where I came across this solution: http://stackoverflow.com/a/20751723/522859

How to Get a JavaScript Stack Trace – Chrome Console

Hey everyone,

Just a quick post on something useful I came across today. In JavaScript you can access the stack trace via console using the following command (ctrl + shift + j):

console.trace()

In Chrome, this will let you navigate to each relevant call by clicking the line number in the console window. I’ve found it pretty useful for backtracking through jQuery exceptions.

For more info, check out this Stackoverflow post: http://stackoverflow.com/q/6715571/522859

Debugging with Exceptions – Ruby on Rails

Ran into a bit of trouble with a model today, after a bit of a google I came across this technique which helped me solve it:

#Raise exception on object.inspect
raise Object.inspect

#Example 1
raise order.inspect

#Example 2
raise [sub_orders.count].inspect

This simply allows you display variable values as an exception. By placing a few of these throughout your troublesome code you can simulate a fully targeted trace.