November 2016 Entries

Keyboard short-cut to get your lost Google Chrome tabs back

Issues: You just accidentally closed your Google Chrome browser, and oh boy, you lost all your open tabs and windows. Google Chrome has a really helpful short-cut to get them all back. You also have similar options in Firefox and other browsers but have to use their menu system to “Reopen closed tabs”. The Solution: In Google Chrome simply use this sort-cut keyboard hotkey: Ctrl+Shift+T If you’re not using Google Chrome, my question is: “Why not?” ......

JavaScript–Adding months or days to a date

Goal: Add moths or days (or other increments) to a date in JavaScript. Solution: var current = new Date(); var threeMonthsInTheFuture = new Date(new Date(current).setMonth(curr... + 3)); for days use: getDate() for hours use: getHours(). and so on… ......

EF Code First Migrations–Create Index with INCLUDE

The problem: Using Entity Framework code first migrations to create a complex index that defines “INCLUDES” as part of the index. Yeah, good luck doing that using Entity Frameworks fluent notation using LINQ ModelBuilder. Btw, the example below is an ASP.Net Core 1.0 implementation. The solution: Plug into the Code First migrations pipeline by simply defining your own custom sql. Create a “dummy” migration file and add the code below that is just using the model builder’s SQL method to run any custom ......

How to enumerate an ENUM (C#)

Goal: You have a C# ENUM and for some reason you would like to enumerate it. Perhaps you would like to return the enumerated list to the client’s ajax call rather than calling the DB table that represents the ENUM. For example you may have invoice statuses and want to build an anonymous list. Result: C# class: public enum InvoiceStatus { [Display(Name = "OPEN")] Open = 1, [Display(Name = "CANCELLED")] Cancel = 2, [Display(Name = "POSTED")] Posted = 3, [Display(Name = "VOIDED")] Void = 4, [Display(Name ......

Entity Framework DbSet Attach() vs Add()

Issue: Two options are available in EF to let it know an object exists, “Attach” and “Add”, not sure when to use which. Answer: “Add” as the verb suggests is for adding new objects to the EF context in order for them to be created/inserted in the database when calling “SaveChanges”. Without using “add” they float around as orphans as it were. The goal of “Add” is NOT to “tell EF about an object that already exists in the DB”. That is what “Attach” is used for: “Hey EF, you didn’t retrieve this object ......

Restore SQL Database–Restoring security user settings

The issue: I just restored a database backup file from somewhere. The users had a problem in a production environment and I want access to the same data to debug. The user (service account) created to access the DB is “Developer”. Why am I telling you this, well context can be useful sometimes So the restore is successful, yippee. I run my web app and it blows up with SQL login failed exceptions. Fail! I read the exception carefully, and oh it mentions “Developer” failed to log in, aha, that should ......