Thursday, August 18, 2011

creating custom short cut snippet in visual studio for MVC

Someone you may know about short cuts in visual studio but do you know how to create your own?

you can use "ctor" and tab tab to get this
public HomeController()
{
}

"prop" and tab tab for
public int MyProperty { get; set; }

but you can create one like "view" to create this
public ActionResult foobar()
{
return View();
}


This is how
1. go here C:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Visual C# (for visual studio 9)
2. copy of those file and change the name to like "view.snippet" and update the xml file.


<?xml version="1.0" encoding="utf-8" ?>

<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

<CodeSnippet Format="1.0.0">

<Header>

<Title>view</Title>

<Shortcut>view</Shortcut>

<Description>Code snippet for an automatically implemented property</Description>

<Author>Wil</Author>

<SnippetTypes>

<SnippetType>Expansion</SnippetType>

</SnippetTypes>

</Header>

<Snippet>

<Declarations>

<Literal>

<ID>name</ID>

<ToolTip>View Name</ToolTip>

<Default>foobar</Default>

</Literal>

</Declarations>

<Code Language="csharp"><![CDATA[public ViewResult $name$()

{

return View();

}]]>

</Code>

</Snippet>

</CodeSnippet>

</CodeSnippets>


Now you type in "view" and tab tab in the HomeController or whatever else and you shoudl get this
public ActionResult foobar()
{
return View();
}


that's all.

more info here http://msdn.microsoft.com/en-us/library/ms165394.aspx

and I used http://www.simplebits.com/cgi-bin/simplecode.pl to convert xml code so that that blogger will allow me to enter the xml code.

Saturday, August 13, 2011

Google Plus Game Development

I am thinking about create a Google+ game using html5 with jQuery.  I just got a game tab from on my Google+ account.  Here is a link to Google+ team about it.  http://googleblog.blogspot.com/2011/08/games-in-google-fun-that-fits-your.html  and google dev team blog here http://googleplusplatform.blogspot.com/2011/08/stepping-onto-google-platform.html.


I just signed up for Google+ developer.  waiting for the email now.


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.