Entity Framework 4.1 now fully supports SQL Server Compact for Code-First Development with ASP.NET MVC 3. There are a few gotchas still, especially considering that CTP versions of libraries had workarounds and are therefore incompatible with the RTM. But since they are still available as NuGet packages, this might be confusing for the beginners. It certainly was for me.
So, here are the steps:
- Create an MVC 3 application.
- Create Model classes.
- Scaffold the controllers and views.
- Add the connection string to Web.Config
- Adjust Global.asax Application Start
This option tells the EF to recreate the database if model changes. Tip: make sure you don't already have the database file created when working with SQL Server Compact, otherwise the following errors pops up