Sunday, April 17, 2011

mvcscaffolding

This is for anyone interested in doing scaffolding in asp.net mvc.

http://blog.stevensanderson.com/2011/01/13/scaffold-your-aspnet-mvc-3-project-with-the-mvcscaffolding-package/

http://channel9.msdn.com/events/MIX/MIX11/FRM13

//get-scaffolder : see what functions are available

Install-Package MvcScaffolding
Update-Package MvcScaffolding
Uninstall-Package MvcScaffolding -RemoveDependencies

Scaffold Controller Team -Force
Scaffold Controller Team –Repository -Force
Scaffold Action Team About -CreateView Model -Force
Scaffold Action Team About -CreateViewModel -Force
Scaffold Action Team About -CreateViewModel -Force -Post

Scaffold UnitTest Team Registration -VewModel AboutViewModel

Scaffold customTemplate UnitTest TestClass
Scaffold customTemplate UnitTest TestMethod

Plural table name error with entity framework 4.1 (code first)

Invalid object name 'dbo.Albums'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.Albums'.

Source Error:

Line 33: // the albums with the highest count
Line 34:
Line 35: return storeDB.Albums
Line 36: .OrderByDescending(a => a.OrderDetails.Count())
Line 37: .Take(count)


If you get this issue then you maybe able to fix it by doing this

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}


and don't forget to reference this

using System.Data.Entity.ModelConfiguration.Conventions;

oh and this needs to be in your a class that inherits DbContext


Hope this helps someone.