React & ASP.NET Core

Update 08 Sep 2019: since Microsoft has officially announce the deprecation of aspnet-webpack package in .NET Core 3.0, you might not want to use the code in this blog post directly in production. However, you might still be able to learn a thing or two from it. I will write a new blog post on restoring all the following feature on the new React template in Visual Studio.

React is getting very popular for building rich web interface, and is one of the supported project template in ASP.NET Core. In .NET Core, you can quickly create a new React project by running the command (or using the new project dialog):

The template immediately gives you a working project with both React and ASP.NET Core. However, I don’t feel very happy with the latest template in .NET Core 2.2 and 3.0, so I created a new one based on the template from older version of .NET Core for my own projects.

Read More

Beta8 and the new hosting model

In ASP.NET6 beta8, Helios (IIS native host) has been removed. Instead you can use Kestrel host and configure IIS server to talk to the host. This hosting model should be very familiar with people using ASP.NET 6 on Linux as they may have already been using this hosting model from previous betas. I won’t write much about the hosting model as Damian Edwards already has a detailed post on that here: https://github.com/aspnet/Announcements/issues/69
However, I will describe some change that everyone that are using Helios on Windows would have to make to their beta7 projects.
Read More

First take on MongoDB

Recently, I have looked around for a good NoSQL database for my new project. I have been using MSSQL for a while but there seems to be more and more complexity as the data models are no longer table-compatible with sub-items and array and a volatile schema.

I have considered DocumentDB on Microsoft Azure on its very interesting indexing capability and the fully managed environment of Azure. However the current price is too expensive for me: 20 USD/month/collection. Some people suggested to put every type into a collection and use a field to distinguish them, but I feel that it is quite messy, especially for NoSQL starter like me. So I went back to some other popular choices such as RavenDB and MongoDB. RavenDB seemed to be a great fit at first as it seems to have very good interface for .NET (C# is my language of choice at the moment) and an awesome web interface, but I then realized that the free version actually has a lot of limit, and I did not plan to incur too much cost on this project.

So I decided to go with MongoDB, which is hugely popular NoSQL database, and seemed to be totally free for my need.

Read More

Commands with Entity Framework’s migration

Supporting for Code-First and Code First Migration are two of many useful features Entity Framework provides us with. However, as far as I know, using Code First Migration still requires us to open the Package Management Console and type in commands. Text commands are very useful when you want to batch or automate them or save them for later use, but they are really painful for inexperienced users.

I found a very good blog post where the guy lists all the necessary commands with Code First Migration with some extra explanation and comments as well. It should be good for anyone who forget some parameters or forget the command get-help.

http://coding.abel.nu/2012/03/ef-migrations-command-reference/

Unfortunately, the blog post does not state how to roll back all the migrations (this is different from re-creating an empty database, especially when EF supports multiple DbContext on one database already). I tried to do that when my database was created in EF6-alpha3, and upgrading to EF6-rc1 required rolling back and removing all migrations created by the alpha version. A quick search on Bing get me the answer I need:

Update-Database -TargetMigration:0

Or

Update-Database -TargetMigration:$InitialDatabase

This one and all the commands in the blog post above should help you to work with Code First Migration in a breeze.