Brush Up Your SQL

Thanks to LINQ and Entity Framework, I don't write a lot of online, transactional SQL any more (I like to think that, thanks to Entity Framework, I have Microsoft's ADO.NET team doing that for me). But there are features in SQL that just aren't available in the current version of LINQ (see my columns on SQL Server 2016's support for JSON and temporal tables for examples).

More

Posted by Peter Vogel on 03/05/20180 comments


Avoiding Entity Framework Slowdown

Generally speaking, I don't worry much about tweaking my LINQ queries when working with Entity Framework (this is also true when I'm working with SQL directly, by the way). I'm always telling my clients that if they want to speed up their data access they should look at their database design and, especially, how they're using indexes.

More

Posted by Peter Vogel on 02/23/20180 comments


The C# Scopes for Privileged Inheritance

You can't really combine the various scopes that you can apply to a C# member because, I suspect, they wouldn't make sense (what's the scope of a public private method, for example?). However, you can combine internal with private and protected like this:

public class CustomerBase
{
  protected internal void DeleteCustomer() {
More

Posted by Peter Vogel on 02/21/20180 comments


Getting Data from the Request Object in ASP.NET MVC

Most of the time in ASP.NET MVC I can count on model binding to fill in the values for the parameters to my Action methods. Every once in a while, though, model binding doesn't do what I expect. You can create your own custom modelbinder to solve this problem (I've even discussed how to do that for the ASP.NET Web API). However, that may be overkill.

More

Posted by Peter Vogel on 02/20/20180 comments


Paste JSON and XML as a Class

I don't use Visual Studio's Edit menu enough, obviously: For some time there's been a Paste Special option on that menu that I didn't know about. It has up to two choices depending on what kind of file you're editing: Paste XML as Classes and Paste JSON as Classes. Using the Paste JSON as Classes option, I can copy some JSON in my JavaScript code and create a corresponding C# or Visual Basic class in my server-side code just by picking a menu the appropriate menu choice.

More

Posted by Peter Vogel on 02/16/20180 comments


Manipulating URLs on the Server

There's nothing stopping you from working with URLs in code using standard string functions. If you want to create a URL, you should use the URL object. On the other hand, if you want to analyze a URL -- or, more properly, a URI -- you should use the Uri class.

More

Posted by Peter Vogel on 02/13/20180 comments


Best Practice: Declare Variables as Constants

In the bad old days, I only used constants as a way to assign names to values. Things like this, for example:

Private Const DaysInWeek As Integer = 7

However, these days most of my variables are holding objects; Some of my other variables are holding things like collections or delegates. That changes what we mean by "constant."

More

Posted by Peter Vogel on 02/12/20180 comments


Pasting Into a Command Window

I amazed a client recently who was looking over my shoulder when I copied a file path from the address in Windows Explorer.

Actually, it wasn't copying the path that impressed him -- it was when I pasted that text into a command window. I clicked in the command window, clicked on the icon at the right-hand end of the command window's title bar and, from the dropdown menu, selected Edit | Paste.

More

Posted by Peter Vogel on 02/09/20180 comments


Load TypeScript Modules as You Need Them

In the bad old days you put all your JavaScript code into a single file and loaded that file on every page that needed any of your code. As the amount of JavaScript code increased, you started organizing your code into files and loading just the files you needed.

Currently, you can organize your code into modules and, for any particular module, specify what other modules it needs. Using a module loader, those other modules will automatically be loaded for you.

More

Posted by Peter Vogel on 02/08/20180 comments


Check That Your Config Files Are Transformed Correctly

Having a process to manage the settings in your application's Web.config file as you move from release to production is essential to ensuring your production Web site works correctly.

One way to handle that is to set up a Web.release.config file with transformation rules to convert your development config file to your production version whenever you compile in Release mode.

More

Posted by Peter Vogel on 01/05/20180 comments


Get Back to the Visual Studio Editor Window Without the Mouse

So your mouse is in some tool pane in Visual Studio and you want to get back to the editor window. You don't have to reach for the mouse -- just press the Escape key. You may have to press the key multiple times but sooner or later, your cursor will probably end up in the editor window. I have to say "probably" because, every once in a while, using Escape won't get you back to the editor window.

More

Posted by Peter Vogel on 11/18/20160 comments


Add a Shortcut to Frequently Visited Code

I had an application with one section I had to work on every couple of months over several years (the client kept changing its collective minds about how it wanted part of the UI -- a search page -- to work). Eventually, I created a shortcut to the section of code I kept having to change so that I could get there quickly. Adding a shortcut is just one step: Click on a line and type Ctrl+K+H.

More

Posted by Peter Vogel on 10/07/20160 comments


Subscribe on YouTube