Entity Framework Code First Demo

I just created my first video on YouTube! In the video I demonstrated creating a database using the Entity Framework Code First workflow. Watch it below!

The Good and Bad of Writing Software

The good thing about writing software is that you can do anything you like. The bad thing about writing software is that you can do anything you like.

Configuration in ASP.NET Core

Lots have changed in the new ASP.NET Core world. From the project structure to the hosting model to the improved Razor engine, the Microsoft team introduced a slew of changes that is more apt for modern web development geared toward the cloud.

One of the big changes is the configuration model. In a non-core ASP.NET project, we store configuration settings in the appsettings section of web.config. This is no longer the case in ASP.NET core projects. In this post we will take a detailed look at the new configuration model.

Adding Google Maps to Your Angular Application

Hi, in this post I will show how to add Google maps to your Angular application. At the end of this post, we will be able to see the map of the United States and we will be able to pan and zoom.

How to Track Pageviews to Your Website using Google Analytics

In this post I will be showing how to add page view tracking to a website using Google Analytics.

Facebook Login with ASP.NET MVC Web Applications

This post is a step-by-step guide on integrating Facebook login with an ASP.NET MVC Web Application. We will start from scratch and end with an application supporting Facebook login.

On Working Remotely

Technology is a great enabler. It allows us to do things that weren't previously possible or that were difficult to do. It also makes existing processes more efficient. This provides benefits not only for businesses but for technology workers as well. In this post, I will share my thoughts about working remotely.

Auditing Changes with Entity Framework

Today we will see how we can keep an audit record of entity changes using Entity Framework. This is a very useful feature that can also be a business requirement when dealing with important or sensitive information.

Design Pattern Spotlight: Adapter Pattern

The Adapter Pattern's intent is: "convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces" (taken from the Design Patterns book). That statement seems intimidating at first, but the core concept is really simple. In fact, I won't be surprised if you are already using this pattern in your application. Let's talk more about it below.

How to View SQL Queries Generated by Entity Framework

Entity Framework works by translating C# code into SQL statements, executing those statements on a target database, and taking care of mapping any return values back to C# objects. But have you ever wondered what the generated SQL statements actually look like? In this post we will be using a free and simple tool that lets us view the SQL executed on the database.

AngularJS AJAX GET and POST Example with ASP.NET MVC JsonResult

A while back I blogged about Using JQuery AJAX GET with ASP.NET MVC JsonResult. This time, we will be talking about using AngularJS for making GET and POST methods using the $http service.

Some Tips on Organizing Code

One of the signposts pointing to clean code is well-organized code files. Contrary to popular belief, aesthetics and organization are important when it comes to writing code, because having organized and structured code improves readability. A piece of code written once will get read multiple times, so it's worth the time to put a little more effort into improving the code's readability. In this post I will be sharing some tips on how to make more organized and readable.

End-to-End Image Upload with Azure Storage, AngularJS, and Web API

A common feature in web applications is image upload. Images can be stored on disk, in the database, or in some other server. In this post we will take the third approach and store images using Azure Storage. We will also be using AngularJS on the front-end and Web API in the back-end.

Developer Mindset - Software as a System

In this post I will share a mindset that would help you build cleaner and more maintainable code. I am calling this as thinking of "Software as a System".

Converting JSON Data Into C# Objects

There are times when we would need to convert JSON string data into C# objects. An example would be when consuming some Web API that returns JSON data. Although we can work with the JSON string data directly, it would be much nicer if we could somehow convert the data into an object, so that we can work with them more easily. In this post we will talk about how to do this.

Libraries and Frameworks

Today we are going to take a look at libraries and frameworks. We will describe each of them and take a look at some examples for each. We will also take a look at a practical example of how being able to distinguish between the two will help us in our daily coding.

Using Bower in Visual Studio

Today we are going to look at a very useful tool for managing client side CSS and JavaScript libraries - Bower.

Why Use ViewModels?

Let's talk about a simple but important topic: why use viewmodels in our web applications. Specifically, the kind of viewmodels that we will be talking about are the ones that are used as parameters or return values in controllers.

Introduction to Dependency Injection - Part 2

In the last post I gave an introduction to dependency injection, where I described what it is, how it can be achieved, and the motivation behind it. We left off by providing an example in an ASP.NET MVC controller, where we manually "newed up" dependencies inside the constructor of a controller. In this post we will take a look at dependency injection frameworks and see how they can help us manage dependencies.

Introduction to Dependency Injection - Part 1

The concept of dependency injection has been around for a long time. But now that dependency injection is baked into ASP.NET Core 1.0, I thought it would be a good time to write about what it is and why and how we can take advantage of it.

This post is part 1 of a two-part series on dependency injection. Click here to go to part two.

Creating Custom Filters in ASP.NET MVC

Whenever ASP.NET MVC receives an HTTP request, the request goes through code in the MVC framework before it reaches our controller actions. And then, after we return from our controller, it also goes through framework code before an HTTP response is emitted. The framework code that is involved is typically called the "pipeline". In this post we will talk about how we can insert our own custom code into the pipeline. This is achieved by creating special classes called filters.

Why I Don't Use the Repository Pattern When Working with Entity Framework

Today I'm going to talk about a slightly controversial topic about using the repository pattern in combination with an ORM such as Entity Framework.

Creating a Generic Lookup Service

In a previous post I talked about how we can manage lookup tables with Entity Framework Code First. In that post I suggested using the primary key directly to check for a specific lookup, rather than introducing an arbitrary column that will serve as an identifier. In this post I will talk about how we can make a generic lookup service to simplify how we show lookup values in, say, dropdown lists.

Managing Lookup Tables with Entity Framework Code First

Oftentimes in our applications we will have such things as a "lookup table". I am defining a lookup table as a list of relatively fixed or static choices such as status codes, states or provinces, and so on. In this post I will share how I manage lookup tables using Entity Framework.

Web Scraping with F#

Web scraping is defined as getting and saving information from an HTML page through a program. In this post we will leverage F# and the HTML type provider to do web scraping.

On Validation and Database Design

SQL Server lets us design tables which have constraints and checks in them. Some examples of these constraints / checks are primary key constraints, nullability flags, maximum length flags, and so on. These checks are used to ensure data integrity. Insert, update, and delete commands which will result in an invalid state when executed are not allowed. However, there are some advantages to not using these checks. In this post, we will talk about some of those advantages.

Strongly-Typed AppSettings

Application settings for .NET projects provide a way to change the behavior of a program without recompilation. These settings are typically stored as key-value pairs in the web.config or app.config files and can be accessed through the ConfigurationManager class provided by the framework. In this post we will be taking configuration access to the next level by providing a strongly-typed wrapper around the ConfigurationManager class.

Publishing an ASP.NET 5 Project to a Local IIS Server

Recently I deployed a new ASP.NET 5 web application to a local IIS server. Though there are several online resources available about deployment, I encountered some problems that were difficult to diagnose and fix. In this post I will talk about the general deployment process and the steps I followed for a successful deployment.

Using AntiForgeryTokens in ASP.NET MVC with AngularJS

Protection against CSRF (use of AntiForgery tokens) is supported in both the ASP.NET MVC and AngularJS frameworks. However, they have different implementations. What this means is that the default implementation of ASP.NET MVC for AntiForgery tokens will not work out-of-the box on an AngularJS front-end. In this post we will look at this in more detail and come up with a solution to the problem.

Integrating Custom Validation with ASP.NET MVC ModelState

One common pattern we see in ASP.NET MVC controller actions is a conditional check for ModelState.IsValid, with different branches getting executed based on whether the result is true or false. The ModelState captures errors arising from data annotations such as Required and StringLength. When there are custom validations that cannot be captured using data annotations, what usually happens is that these validations are checked in the success block of ModelState.IsValid. In this post we are going to talk about how to integrate custom validation into ModelState.