ASP.NET MVC 3 - Razor based blog engine with SQL CE 4.0
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

New comment
Comments
03/01/2011 by Mr B
Regards.
04/08/2011 by Victor | http://www.victorfabregat.com.ar
Second - you really need to give your blog a name if you want it to succeed! How about "Frog Blog":-}
FYI - EF 4.1 was released to day and, unfortunately, Microsoft changed something which causes an error - "Invalid Column Name" Tab_Id, Tab_Id, BlogEntry_Id after upgrading (see http://social.msdn.microsoft.com/Forums/en-SG/adodotnetentityframework/thread/740d94a4-f575-4a5b-90e8-7533feb8708f). One way to fix the error is to rename the columns in TagBlogEntries to be: BlogEntry_Id and Tab_Id respectively.
It'll be very interesting to see how it stacks up against FunnelWeb and NBlog.
04/13/2011 by Joe
Thanks for your input. I have upgraded the database in the download. EF 4.1 is now supported.
I will think about giving my blog a name. But maybe there is a better choice than "Frog Blog" :-)
04/13/2011 by Daniel
I have download ur MVCBlog.zip file
but when i run the application the following error generate
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Views/Blog/Index.cshtml
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225
Please give the solution
Thanks
shamim
07/12/2011 by Md.Samnur Rahman
In ASP.NET MVC the URL is not directly mapped to a view.
URLs are mapped to controller actions which may render any view.
Just try '/Blog' as URL, and it will work.
07/12/2011 by Daniel
Thank you for your answer. Its works properly.
07/13/2011 by Md.Samnur Rahman
Why? Please give me a solution.
07/17/2011 by Md.Samnur Rahman
I'm sorry, but since I don't know anything about your CSS customization, I can't help you. But with Firebug it will be easy to find out how which CSS rules are applied.
07/18/2011 by Daniel
I am try to publish asp.net mvc3 but no success find from this publish.
My server configuration is given bellow:
This is Windows 2008 ( IIS 7.5 ) Server Hosting Info with
asp.net Framework Version 4.0, 3.5, 3.0, 2.0, ASP.net MVC2/MVC3
MSSQL 2008 R2 & 2005 , MySQL 5.0.45, PHP 5.2.13 ,
Apache Tomcat 5.5.4 SQL Server Management Tool : mylittleadmin
I am try to the following steps:
step 1: Solution Configuration change to Release mode.
step 2: Build the Complete solution
step 3: Expend the solution explorer and right click on the website.
step 4: select publish and publish web pop up dialog open.
step 5: select publish method FTP from the dropdown.
step 6: In the target location text box put the following url
http://authoritysql.com:8880
step 7: Delete all existing file prior to publish radio button checked.
step 8: Credential passive mode checked.
step 9: Finally put cpanel user name and password and the press publish.
Please give me a step by step solution.
07/20/2011 by Md.Samnur Rahman
Your server seems to be suited for the application.
But since you didn't provide any error details, I can't help you.
But Google will help you to find a solution.
07/20/2011 by Daniel
07/28/2011 by ASP .Net Web Development | http://www.vinfotech.com/web-development/asp.net-web-application-development.htm
/****** Object: Table [dbo].[TagBlogEntries] Script Date: 02/07/2011 19:05:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TagBlogEntries]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TagBlogEntries](
---------------------------------------------------------------
-- The errors have been fixed here:
[BlogEntry_Id] [uniqueidentifier] NOT NULL,
[Tag_Id] [uniqueidentifier] NOT NULL,
---------------------------------------------------------------
CONSTRAINT [PK_BlogEntry2Tag] PRIMARY KEY CLUSTERED
(
[BlogEntry_Id] ASC,
[Tag_Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
END
GO
08/09/2011 by Kaush
Thanks for your hint. I fixed the script.
08/10/2011 by Daniel
I will eventully place in the footer section its orgin. It really should point back to you in a public way.
08/12/2011 by Benny Morgan | http://www.benny-morgan.com
Thanks for the feedback.
08/12/2011 by Daniel
Thankys for your efforts!!
09/17/2011 by HS park | http://kkojabee.tistory.com
09/22/2011 by jahir
10/27/2011 by simon
10/27/2011 by simon
There is only one login, which can be changed in Web.config. See my readme (included in the download) for details.
10/27/2011 by Daniel