Dev How-To Archive

These are how-to articles from my days as an asp.net coder. They were things that I wanted to document but mostly couldn’t easily find other resources for. Now that I have moved into dev management, these topics will be old and mostly obsolete. However, I keep them here to accommodate links elsewhere on the web.

What we can all learn from Stack Overflow’s security incident

Stack Overflow had a security breach, and they have generously shared the details of how a hacker worked through multiple layers of security over 11 days. They gained access to source code, security keys, build processes, and some PII. Reading their account (at https://stackoverflow.blog/2021/01/25/a-deeper-dive-into-our-may-2019-security-incident) really brought home an important lesson… small issues in overlapping layers…

How to Sort a Generic List of Objects

The Situation You are trying to sort a Generic List of Objects based on a property of the Objects. A Solution There are two easy options for sorting a Generic List populated with Objects: in place and sorting to a new List. Use Linq. “In Place” sorting of an existing List (the code below only…

How To Extend the Timeout Period on an Entity Framework Query

The Situation: You have a long running Entity Framework query that often creates a “System.Data.SqlClient.SqlException” with the message “Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.” A Solution: As near as I can find, the default timeout for EF queries using the SQL Server 2008…

How To Perform a Callback on an ASPxGridLookup Control

The Situation: You have a DevExpress ASPxGridLookup control on your page and need to update its contents when some event occurs (such as a parent drop-down value changes). The problem is that the ASPxGridLookup control does not implement an OnCallback event. A Solution: First of all, this is not my solution. I found it on…

How to Convert a Generic List to a Comma-Delimited List

The Situation: You have a List<string> and need to convert it to a comma-delimited list (for display or storage). A Solution: This is a great example of how C# has improved over the years. I found this solution in this StackOverflow discussion and don’t want to lose it, so I am copying it here for…

How to Add a New Table to an Existing Database via EF Code-First Migrations

The Situation: You have been using Entity Framework code-first migrations with an existing database. Making changes to an existing table, such as adding a new field, go smoothly, and the database is updated correctly when you run an “Update-database” command. However, when you create an entirely new entity in your model and run “Update-database”, the…

How to Enable and Use EF Code-First Migrations for Multiple Contexts

The Situation You want to use Entity Frameworks code-first migrations to push model changes to the database, but you have multiple databases and contexts in your model. When you try to run Enable-Migrations for the second context, you get an error that looks like this: Migrations have already been enabled in project ‘Project1’. To overwrite the…


Follow My Blog

Get new content delivered directly to your inbox.