Suppress Columns in Entity Framework Code-First

I'm not a big fan of what I call "aggressive code-first," where your table design is derived from your object design. And, to tell you the truth, I'm not sure I have a good reason for my skepticism. With the one client I worked for who used this process, everything worked out fine (by which I mean that the table design we ended up with was exactly the one I would have recommended).

More

Posted by Peter Vogel on 09/30/20160 comments


Label Your Breakpoints

With more recent versions of Visual Studio, breakpoints you set in your code are saved from one editing session to another. Because you might not always want to stop on those breakpoints, however, you will want to selectively enable and disable them. To facilitate that, from the Debug | Windows menu choice, open the Breakpoints window to view (and manage) all of your breakpoints. From this window you can, for example, double-click on any of the listed breakpoints to be taken to its position in your source code.

More

Posted by Peter Vogel on 09/26/20160 comments


Doing Calculations Right with the Math Class

The .NET Framework gives you the Math class, which has a ton of methods and properties that you can use.

The Abs function will convert negative numbers to positive (and leave positive numbers alone), while the Sign method will tell you if a number is positive, negative or zero.

More

Posted by Peter Vogel on 09/15/20160 comments


Always Go to Production in Release Mode

I was at a client's site recently and watched them move the new version of their app to production by copying all the DLLs from the "staging" computer to the production computer. I commented on how that was the beauty of the .NET Framework: Once you had the application installed, upgrades could just consist of replacing the EXEs and DLLs. Of course, I added, you have to remember to do one last compile in Release mode before copying the DLLs.

More

Posted by Peter Vogel on 09/09/20160 comments


Maximize Your Visual Studio Editor Window Space Fast

When I'm writing code, I like to devote as much screen space in Visual Studio to my editor window as possible. I did a tip earlier on how to get into Visual Studio's full screen mode where your entire screen becomes your editor window. However, I understand that full screen mode might not be your cup of tea because getting to the various tool windows -- Solution Explorer, for example -- isn't obvious (you also lose the window's title bar with the standard maximize/minimize/reset buttons).

More

Posted by Peter Vogel on 09/01/20160 comments


Make Sure You're Compressing What You Send to the Browser

This is really a tip for IIS 7 (or later) Web site administrators than it is for developers: Make sure that you've looked at how you're using urlCompression your site. urlCompression ensures that, when the browser supports it, your Web pages and static resources (PDF files, for example) are compressed before being sent to the user. This can reduce the amount of bandwidth used on each user request.

More

Posted by Peter Vogel on 08/25/20160 comments


Visual Studio Toolbox Shortcuts: Expand, Collapse, and Find

With the rise of ASP.NET MVC, the role of the visual designers that were so much a part of creating UIs have diminished and that's too bad. If you're using one of the UI development technologies that give you a Visual Designer with toolbox, here are three tips you might not know to make working with your toolbox easier. After clicking on the toolbox (or otherwise making it active), if you type

More

Posted by Peter Vogel on 08/12/20160 comments


Add an Error Handler to Your ASP.NET MVC Controller

There really isn't such a thing as an "unhandled error" -- if your code throws an error outside of a Try...Catch block, then your error bubbles up through various ASP.NET and .NET Framework error handlers. An "unhandled error" is just an error that you aren't handling.

In ASP.NET MVC you can handle more errors by inserting an error handler inside your Controller: Just add an OnException method to your Controller. The code in this method will be invoked each time you have an "unhandled error" in that Controller.

More

Posted by Peter Vogel on 08/09/20160 comments


What Version of ASP.NET MVC Are You Using?

Prior to the pause in releases triggered by the latest structural changes to the .NET Framework, it seemed like the ASP.NET MVC team was releasing a new version in any month whose name ended with a letter. As a result, you could easily find yourself supporting multiple applications, each with its own version of ASP.NET MVC. Alternatively, you might have just taken over support for an ASP.NET MVC application and be wondering what version your application is using.

More

Posted by Peter Vogel on 07/29/20160 comments


Including the Location of Your Error in Your Error Message

A user calls you to complain that your code has thrown an exception. You ask the user to read the message to you … and you realize that you have no idea where that error comes from. You would know if you'd included the Exception object's TargetSite property in your error message because that property reports on the method that had the problem.

More

Posted by Peter Vogel on 07/22/20160 comments


Write to Visual Studio's Output Window on Your Breakpoints

I can't tell you the number of times I've put a breakpoint inside a loop so that I could stop each time I go through the loop and check the value of some variable or property. Unfortunately, by the third or fourth trip through the loop I've forgotten what the values were on my first trip through the loop.

More

Posted by Peter Vogel on 06/23/20160 comments


Save Some Time Deleting Entities in Entity Framework: RemoveRange

When it comes to speeding up your application, your best opportunity is to reduce trips to your database. So, when you see a method like RemoveRange on a DbContext collection, you might think that's an opportunity to delete a bunch of objects in less time than deleting those same objects one by one. You'd be right…but not because you're saving trips to your database.

More

Posted by Peter Vogel on 06/21/20160 comments


Subscribe on YouTube