About one year ago a created a blog engine which was based on ASP.NET MVC 1. Since then technologies have evolved. When ASP.NET MVC 3 was released, I decided to update my blog engine to use the new RazorViewEngine. Instead of MSSQL Express I use Microsoft SQL Server Compact 4.0 together with the new Entity Framework 'Code First' approach.
Features/Setup
The features of the blog engine are described in this post.
The setup of the blog engine is quite easy. The directory 'Setup' contains a readme explaining the necessary steps.
Requirements
- .NET Framework 4.0
- ASP.NET MVC 3
- Entity Framework 4.1
- SQL CE 4.0 or MSSQL 2005/2008 (Express)
Implementation
ASP.NET MVC 3
Creating views with MVC 3 is very comfortable with the new RazorViewEngine. The markup is definitely cleaner and more readable.
Validation can now be performed using ValidationAttributes in your model classes.
Together with Unobtrusive JavaScript you can display nice validation messages in your views without using inline JavaScript.
Another advantage of MVC 3 is, that in Global.asax.cs you can define attributes that are applied to all controllers. This is quite useful, since it is no more possible to forget important filters on new controllers:
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new System.Web.Mvc.HandleErrorAttribute()); }
Scott Guthrie describes all the new features on his blog.
Entity Framework 'Code First'
Working with the 'Code First' approach seems to be quite great, especially when you are starting without an existing database. To get started, you have to define your entities as POCOs. Then you optionally add some constraint and validation attributes on the properties:
public class Tag { [StringLength(30)] [Required] public string Name { get; set; }public virtual ICollection<BlogEntry> BlogEntries { get; set; } }
When you launch the application for the first time, your schema gets automatically generated.
The ADO.NET team has a nice blog series, which describe the 'Code First' approach with great detail.
SQL CE 4.0
I decided to use the Microsoft SQL Server Compact 4.0 instead of a MSSQL Express database.
Its advantage is, that no installation is required for usage. All you need are two DLLs, which have to be placed in your bin-folder.
If you have problems to deploy your SQL CE 4.0 database, read this post: http://stackoverflow.com/questions/3468981/how-to-deploy-sql-ce-4-ctp-to-shared-hosting
Visual Studio 2010 does not yet have tooling support for managing CE databases, but you could use SQL Server Compact Toolbox instead.
With VS 2010 SP1 you can also use Visual Studio 2010 SP1 Tools for SQL Server Compact 4.0.
Screenshot
Source code
The source code is available for download. You may modify and extend it as you like.
Updates
05.03.2011: Since SQL CE 4 does not support nvarchar(max), I have fixed an issue in Core.Entities.BlogEntry. If you are NOT using SQL CE 4 take a look at the TODO in this file.
14.04.2011: The final release of Entity Framework 4.0 is now supported.
10.08.2011: Dependencies now managed with NuGet
06.09.2013: I have upgraded the blog engine to ASP.NET MVC 4 and Twitter Bootstrap 3.
16.06.2019: Migrated to ASP.NET Core 2.2.