Friday, October 28, 2016

Set up Docker containers on Windows 10 or Windows Server 2016

If you want to get started using Docker for either Windows 10 or Windows Server 2016, you can follow these quick start guides on how to set up Docker containers for each of these respective platforms:

Windows Containers on Windows 10
https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/quick_start_windows_10

Windows Containers on Windows Serverhttps://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/quick_start_windows_server


Tuesday, October 25, 2016

Upgrading to Windows Server 2016

Now that Windows Server 2016 has gone RTM, I thought I would try to see if I can upgrade my existing Windows Server 2012 R2 systems to Windows Server 2016.

As part of the upgrade process, I had to uninstall "VMWare Tools" and "Mcafee VirusScan Enterprise 8.8i" before proceeding with the upgrade as you will see in the screenshots below:














After completing the upgrade, I had to re-install VMWare Tools (since I uninstalled them earlier), but other than that, all of my applications seemed to working fine and intact!  Piece of cake!!

Configuring NuGet for Telerik's Private NuGet feed

If you are a licensed user of Telerik's products, you can configure NuGet on your system to authenticate to Telerik's private NuGet feed using the instructions provided here: http://docs.telerik.com/kendo-ui/aspnet-mvc/nuget-install

Unfortunately, since you cannot configure authentication credentials via the Visual Studio User Interface, you will have to do this through the command line.

Alternatively, you can also set up your own Private NuGet feed following the instructions provided here: http://www.telerik.com/blogs/power-your-projects-with-telerik---now-with-the-convenience-of-nuget

If you follow this option, you simply download the NuGet packages from your downloads available in your Telerik account and then upload them to your private NuGet feed in order to make them available to all of your developers.

That is all there is to making Telerik packages readily available via NuGet!

Friday, October 21, 2016

Performing Entity Framework Code First Migrations step-by-step

If you need to perform Entity Framework Code First Migrations, you will probably end up following this article: https://msdn.microsoft.com/en-us/data/jj591621(v=vs.113).aspx

However, as with most Microsoft articles, the documentation leaves a lot to be desired...

Therefore, I will provide a more thorough step-by-step walk through on just how to do this!


  1. After opening up the Package Manager Console, you will want to make sure you choose the "Default project" before running the command to "Enable-Migrations"


  2. This will then create a Configuration.cs file shown as follows:



  3. Next, when you run "Add-Migration <MyMigrationName>", then you will get the following message along with the migration file added to your project:



  4. You can then run the "Update-Database" command if you want to run the command directly against the database. However, if you are like most developers and want to know what the database script looks like before it is applied to the database, you can instead run the "Update-Database -Script" command which will generate a SQL script instead which you can then save off for reference!


  5. For every change each developer makes to the Entity Framework Code First models, you simply repeat the "Add-Migration" and "Update-Database" steps respectively (corresponding to the Code First model changes that were made) and you can ignore the "Enable-Migrations" command.  That is all there really is to it! :-) 

Dependency Injection with ASP.NET Web Forms

Most developers have used Dependency Injection with ASP.NET MVC and ASP.NET Web API, but it has typically been difficult to set up Dependency Injection with an IoC (Inversion of Control) container.

Well, now Microsoft is offering guidance on how to set up Dependency Injection with an IoC container such as AutoFac for use within your ASP.NET Web Forms applications: https://blogs.msdn.microsoft.com/webdev/2016/10/19/modern-asp-net-web-forms-development-dependency-injection/

While using Dependency Injection in an ASP.NET Web Forms does not remove all of the problems typically associated with developing ASP.NET Web Forms applications, but it does go a long way to reduce the code dependencies found in Code Behind files and makes the overall code base that much cleaner!

Windows 10 Licensed Virtual Machines available for download!

In the past whenever you have wanted to download a Windows Virtual Machine from Microsoft, you would only be able to download an evaluation virtual machine that would expire after a certain period of time.

Of course, for those developers that wanted a non-expiring virtual machine they could immediately download and license, this was a bit frustrating.

Thankfully, though, Microsoft listened to its user feedback and is now offering licensed Windows 10 Pro virtual machines!

You can read more about these Windows 10 Pro Virtual Machines here: https://blogs.windows.com/buildingapps/2016/09/30/just-released-windows-developer-virtual-machines-september-2016-build/#6eQPtyU0dF6M78Qq.97

You can then download the licensed Windows 10 Pro Virtual Machines from here: https://developer.microsoft.com/en-us/windows/downloads/virtual-machines

Tuesday, October 18, 2016

FREE Time Tracking solution

If you have a need to track time for your development team members, there are a number of invoicing solutions out there, but most of them cost $$.

Therefore, if you are looking for an FREE time tracking solution, then you should look no further than TMetric!

https://tmetric.com/pricing/

The current promotion for TMetric provides FREE hosted Time Tracking for a limited time, but will eventually move to a $3/user/month model.

Even at the pricing structure, this is much more inexpensive and affordable than similar time tracking solutions so it is definitely worth your while to check out this solution!


Handling multiple Foreign Keys to the same database table in Entity Framework Code First

I recently encountered a requirement while working with Entity Framework Code First that required mapping more than 2 foreign keys to the same database table.

The convention for Entity Framework Code First, by default, does not make this easy simply by defining [ForeignKey] Data Annotations.

Fortunately, a quick search turned up this Stack Overflow thread: http://stackoverflow.com/questions/5559043/entity-framework-code-first-two-foreign-keys-from-same-table

This thread ultimately resulted in 2 possible solutions to this problem.

The first solution required the usage of the FluentAPI for Entity Framework Code First by relying on the OnModelCreating event in the DbContext class:



The second solution required the use of the [InverseProperty] Data Annotation instead:

Using LINQPad to test and query with Entity Framework

If you want to easily test out your Entity Framework assemblies without writing a separate Console application or creating a separate Visual Studio project, the best way to do this is to use LINQPad!

I have been using LINQPad for several years for all of my C# development needs including Entity Framework, but I have never shared a Blog post about how to do this in the past.

If you go to the LINQPad site, you can find a brief article on how to work with Entity Framework here: http://www.linqpad.net/EntityFramework.aspx

However, this article is not quite comprehensive and leaves out a number of pieces, therefore, I thought I would share a step-by-step article for those working with Entity Framework.


  1. Open up LINQPad and in the left hand navigation, you will see an option to "Add connection"
  2. You will then be presented with a dialog to select your Entity Framework connection.  For most developers using Entity Framework v. 4.1 or above, you will choose the Entity Framework (DbContext) option.
  3. Once you have chosen your desired Entity Framework connection, you will be presented with another dialog which allows you to choose your Entity Framework assembly
  4. Once you choose your Entity Framework assembly, you will be required to choose the corresponding DbContext for your Entity Framework assembly
  5. Next, you will be required to specify a connection string for your Entity Framework assembly. For most developers, you will choose the option for "Via the parameterless constructor" which will subsequently require you to select the database connection string from an App.config file
  6. Then, you will have to choose the path to the App.config file (which will be usually named something like MyAssembly.dll.config)
  7. Lastly, you will need to choose a name for your Entity Framework connection.
  8. Once all necessary information has been entered, you can "Test" your connection.
  9. If the test is successful, you can click on "OK" for the Test dialog and then click on "OK" again so that your Entity Framework connection is added to LINQPad!
  10. Now, to use this connection in your Entity Framework queries, you can click on the newly created connection hyperlink for "Use <my>connection" or you can select your connection from the "Connection" dropdownlist.  
  11. After this is complete, you are all set to begin writing queries against your Entity Framework assembly in the LINQPad Query window!  Woo hoo!














Monday, October 17, 2016

Entity Framework Database First vs Entity Framework Code First connection strings

If you look on http://connectionstrings.com, unfortunately, you will not find sample connection strings for Entity Framework (either Database First or Code First).

Most developers that initially started working with Entity Framework, probably have been using Entity Framework Database First and therefore are familiar with the common lengthy connection string as follows:



However, the Entity Framework Code First connection strings follow the more standard ADO.NET model for database connection strings such as the following:


You can read more about the differences between the 2 Entity Framework models here: https://msdn.microsoft.com/en-us/data/jj556606%28v=vs.113%29.aspx?f=255&MSPPError=-2147217396

Thursday, October 6, 2016

Creating lowercase routes in ASP.NET Web API

When it comes to creating lowercase routes in ASP.NET Web API, there is no built-in facility to automatically lowercase all of your routes as is the case with ASP.NET MVC.

However, you can still solve this issue without resorting to Attribute-based routing and manually writing all of your routes in lowercase.

This can be accomplished through Custom Route Constraints.  In this instance, you will want to create a Custom Route Constraint which simply translates all of the default ASP.NET Web API routes into their corresponding lowercase version.

You can write a LowercaseRouteConstraint as follows:


Creating Route Constraints using Attribute-based Routing in ASP.NET Web API

When you are writing your Web API methods, you may encounter a situation whereby you have two different methods that need to be distinguished from each other through their routes?

For example, if you have a method GetById(int id) and GetById(string id), how do you distinguish between these 2 routes when documenting your Web API using Attribute-based routing?

Well, through Route Constraints of course!

https://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2#constraints

Therefore, you can then have Web API methods like the following:


Tuesday, October 4, 2016

Visual Studio Partner Offers-The offer that you selected is only available to Visual Studio subscribers.

If you are an MSDN Subscriber (which you can obtain through a variety of means such as through the Microsoft Partner Network), you may be interested in using Visual Studio Partner Offers.

Generally, you can access all of the MSDN Partner offers through here: https://vspartner.com/vspartneroffers



However, once you click on a Partner Offer, you will be prompted for a Subscription ID:


Unfortunately, if you own an MSDN Subscription through a Microsoft Partnership for example and you enter your MSDN Subscription ID, you will get the following  message:


In the past, I was able to redeem these Partner Offers!!  However, Microsoft has since changed their policy towards Partner Offers and now they reject everyone except direct paid subscription customers!!

Therefore, even as a Microsoft Partner or if you own an MSDN Subscription through some other channel, you are now excluded from many of the benefits offered to other MSDN Subscribers!  This reduces the overall benefit I (and I am sure many others) used to gain from having an MSDN Subscription!

UPDATE: Microsoft has updated the way you access these benefits and you can now access these MSDN Benefits by logging into this Url insteadhttps://my.visualstudio.com/benefits

Is .NET Core ready for Business/Enterprise development?

If you have read all of the hype on .NET Core/ASP.NET Core, you may be wondering if ASP.NET Core is TRULY ready for Business/Enterprise development.

The best way to judge this for yourself is to read the recent MSDN Blogs:

https://blogs.msdn.microsoft.com/dotnet/2016/09/21/reusing-configuration-files-in-asp-net-core/

In this article, you can see that you have to COMPLETELY re-write functionality for reading configuration files if you decide to move to ASP.NET Core 1.0!!

Next up, if you look at the roadmap for .NET Core, you will see that there are several enhancements already planned for an upcoming release of .NET Core:  https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/

Therefore, Microsoft is basically acknowledging that .NET Core 1.0 is NOT ready for most businesses/enterprises to adopt since a lot of the functionality that developers have used in the past with ASP.NET MVC 5 and ASP.NET Web API 2.2 and other features in the .NET Framework are simply not available in .NET Core today.

This is rather unfortunate since .NET Core brings a lot of exciting features to the table including cross-platform compatibility.  However, the fact is that most developers will end up writing a TON of code to fill in the gaps currently left open by .NET Core 1.0.

On the bright side, much like ASP.NET MVC in its infancy several years ago, it seems that .NET Core will evolve rather quickly to be able to be used in the near future.  I am crossing my fingers and hoping that these features get added sooner rather than later, but given how many years I have been working with Microsoft products, I know not to have too many high expectations.  After all, there are features in some products that took 10 or more years before they were introduced into platforms such as SQL Server, Visual Studio, Team Foundation Server etc. and even in ASP.NET MVC 5 today, there are many features lacking that make it as usable a web development framework as ASP.NET Web Forms...

Saturday, October 1, 2016

Running Code Coverage for Unit Tests in Visual Studio 2015

If you want to run Code Coverage for your Unit Tests, unfortunately, you will need to use Visual Studio 2015 Enterprise Edition.  Visual Studio 2015 Professional Edition still does not offer this crucial feature for most .NET Developers.

In any case, once you run the Unit Tests for your application from within Test Explorer, you can click on the "Run.." link to pull down the drop down menu options:


From there, you can select the option for "Analyze Code Coverage for All Tests", which will then present you with a "Code Coverage Results" pane:


Within the "Code Coverage Results" pane, you can further drill down into your individual namespaces and classes to determine how well your Unit Tests are covering your code!