Hanalei, Hawaii 9/2/2010
438 Posts and Counting

Putting the “M” Back in MVC

Tuesday, March 31, 2009 -

Trying to keep up my end of the bargain with respect to MVC and SubSonic :). I did a walkthrough of it and decided that I was talking too much and, in honor of everyone telling me "SubSonic is dead" I thought it fitting to toss in some Rob Zombie.

Download the template from here.

Download the video from here.

(Double click to watch full-screen)

Related


Gravatar
robconery - Wednesday, April 08, 2009 - Thanks Jonathan - I'm trying to build out a template sharing site right now

so hold tight to those...
Gravatar
Andre Carlucci - Wednesday, April 08, 2009 - Woow! Great stuff!

Also, lots of brazilian artists in your database :)
Gravatar
jchannon - Wednesday, April 08, 2009 - Rob,



I have edited your classes.tt/settings.tt files so they output to seperate files for each table. I have added in a couple of DataAnnotations on the model classes. I have also added a bit at the bottom of classes.tt file which produces a new partial class file to handle any business rule checking the user may want to do outside the actual model class file. This file will not get overwritten if it already exists when the custom tool is run. If you want the files, feel free to contact me.
Gravatar
jchannon - Friday, April 03, 2009 - I changed the repository to FindTableByClassName and that has fixed it for now but I will log the issue for you if you want?



Keep up the good work!



Thanks



P.S. How do you juggle your busy life. I've just had a baby and finding it very difficult but it must be twice as hard for you!
Gravatar
robconery - Friday, April 03, 2009 - Hmm - could be. Can you log it for me here:

http://code.google.com/p/subsonicthree/issues/list
Gravatar
jchannon - Friday, April 03, 2009 - Rob,



Not sure if this is a bug or not but I have changed the database to the one provided by the NerdDinner example. My generated model class is Dinner but when I call repositoy.Update it fails as it cannot find the table in the collection. I pass over Dinner as the item being edited



BuildUpdateQuery(item);

ITable tbl = _db.FindTable(typeof(T).Name); /** Fails **/



typeof(T).Name = Dinner



I have gone down a few levels and I think its because the Name in the DataProvider is Dinners. The DataProvider has all the tables etc in its collection but DataProvider.Tables[2].Name is Dinners so thats why the FindTable fails.



Is this something I have done or a Subsonic3 bug?



Thanks
Gravatar
adolfojp - Thursday, April 02, 2009 - I tried this and now I can create a new Artist without specifying a name. It broke the entire validation.
Gravatar
adolfojp - Thursday, April 02, 2009 - He is actually Rob Zombie.
Gravatar
Johan - Thursday, April 02, 2009 - A litte more research yields that what's needed is to exclude the key property from the binding, like this:



public ActionResult Create([Bind(Exclude="ArtistId")]Artist item) {

...

}



That will make the ModelState.IsValid true. There might be some other way too, but this seems like the right way to do it. After all, you do want to ignore the auto generated id property when creating a new object. Now I'm going to see if I can change this is the template, since I'm not patient enough to wait for a fixed version.
Gravatar
adolfojp - Thursday, April 02, 2009 - I am getting the same error.
Gravatar
adolfojp - Thursday, April 02, 2009 - How I wish that I could help you but I am nothing more than a grunt.



I also wish that I had your patience in dealing with self-entitled people like me who see a free product and bitch and moan and yell "WHY HAVEN'T YOU FINISHED ALREADY!"! :-P
Gravatar
robconery - Thursday, April 02, 2009 - The thing that's been holding me up is a snare with the linq parser. I've

decided it doesn't matter (edge case SQL) and am now getting the docs

together.
Gravatar
Johan - Thursday, April 02, 2009 - When I download the template and try to follow your example, everything works fine except for one thing: When I try to create a new artist, the validation fails, and it says that a value is required for ID. Which is kind of wrong, as it is an auto incremented field.



The same thing happens if I create a table of my own in the db and generate the classes again. So I'm wondering if this is a bug in the template, or just my computer that doesn't work (which wouldn't surprise me one bit).
Gravatar
adolfojp - Thursday, April 02, 2009 - You're the ultimate tease Mr. Conery!



I've been in love with SubSonic since its release, however, I had to stop using it when the latest upcoming release went to live in limbo.



Now you show us this and make us giggle like junior high school girls who are waiting for the next Jonas Brothers movie while we sit and wait for the next SubSonic and groan about the gigantic configuration forests that our current frameworks make us use.



:'(
Gravatar
Khalid Abuhakmeh - Thursday, April 02, 2009 - W00t indeed! The Authorization thing was awesome. So.... where do I type the rake command.
Gravatar
Chris Kolenko - Thursday, April 02, 2009 - Not dead yet !! Classic
Gravatar
Adam - Wednesday, April 01, 2009 - Great work Rob.

Does this work with MySql?
Gravatar
Bill - Wednesday, April 01, 2009 - Ok .... I am officially a bucket head.... when I went to confirm MVC it was RC not version 1.

Thanks for th quick response.
Gravatar
Bill - Wednesday, April 01, 2009 - Yes I do and using VS2008
Gravatar
robconery - Wednesday, April 01, 2009 - Do you have MVC 1.0 installed?
Gravatar
Bill - Wednesday, April 01, 2009 - Rob,



Thanks for all the great work, I have what I think might be a brain cramp. Just tried the MVC template and when trying to add a controller I get the following errors:



CS0117:Compiling transformation:

Microsoft.VisualStudio.Web.MVC.MvcTextTemplateHost does not contain a definition for ControllerName



It looks like variables are not getting filled in, or I have not configured something.



Any idea what the heck I am cramping up on.



Thanks
Gravatar
jchannon - Wednesday, April 01, 2009 - Is it possible to have the entity classes in a seperate file?



Is there a link to explain how all this seems to magically work, I assume its the tt files!



Thanks
Gravatar
jchannon - Wednesday, April 01, 2009 - Ignore me..
Gravatar
jchannon - Wednesday, April 01, 2009 - Impressive dude!



What version of Subsonic does this video use?

Gravatar
robconery - Tuesday, March 31, 2009 - Reset the connection string name in _Settings.tt to point to your new

connection string. Right-click on Classes and Context, and "Run Custom

Tool". I should have added this.
Gravatar
robconery - Tuesday, March 31, 2009 - Probably - not quite sure how to do that just yet :)
Gravatar
rocklau - Tuesday, March 31, 2009 - rob,

how can i make new model with t4 if i will insert new table to database?

Gravatar
jongalloway - Tuesday, March 31, 2009 - Very nice! If there was a Buy button at the end of the video I'd have clicked on it like crazy.



Minor question - is it possible to hide the "Private Implementation Details" classes in the strongly typed view dropdown?
Gravatar
GregRoberts - Tuesday, March 31, 2009 - Good on ya for bringin back subsonic and rob zombie... Seriously though, we knew subsonic wasn't dead, but rob zombie was pretty close.
Gravatar
robconery - Tuesday, March 31, 2009 - You are correct - I spotted it after I pushed the video :). I also forgot to

show off the jQuery calendar and dropdowns on the editor...
Gravatar
William - Tuesday, March 31, 2009 - Was it just me or did the update from "Rob Conery" to "Rob Conery Wahoo!" not work? Seems that the auto-complete didn't pick up the new name nor when you went to delete the item the name was wrong too or am I out to lunch?
Gravatar
dale - Tuesday, March 31, 2009 - Kind of like the RoR screencasts. But with balls thanx to Rob Zombie audio.



Excellent demo
Gravatar
kevintechie - Tuesday, March 31, 2009 - Dude, YOU'RE the zombie!
Gravatar
Nathan - Tuesday, March 31, 2009 - Loved it! Might have some ammo for the guys at work. ;)
Gravatar
Joe Chung - Tuesday, March 31, 2009 - Rock on, Rob! Nice video!
Gravatar
Ben - Tuesday, March 31, 2009 - That's impressive. I considered using subsonic and asp.net mvc. Now I know I have to try it.
Gravatar
educobuci - Tuesday, March 31, 2009 - Wow really happy to see Subsonic kicking!

[OFF] This database (Chinook) has some really goods artists picks. Specially the brazilians :P [/OFF]



Congrats!
Gravatar
robconery - Tuesday, March 31, 2009 - Hrrmph. Was it dead ? :p
Gravatar
Tom L - Tuesday, March 31, 2009 - Very nice Rob. Glad to see you using the post MVC downtime to revive this project.



Also nice touch on Dragula
Gravatar
Chad Moran - Tuesday, March 31, 2009 - Hey Rob, another great video.



I think you've finally convinced me to drop L2S and try out SubSonic. Nice touch with the OpenID integration. Impressive.



Keep it up.
Gravatar
Nathan Totten - Tuesday, March 31, 2009 - Awesome! I will definitely be using this soon.
Gravatar
PabloBlamirez - Tuesday, March 31, 2009 - Awsum sauce :-)
Gravatar
EricTN - Tuesday, March 31, 2009 - Subsonic brings the "M", template makes it fly

Conery's done it again, MVC won't die...
Gravatar
Eric Hexter - Tuesday, March 31, 2009 - good stuff.. nice to see someone putting together some low-friction solutions!
Gravatar
robconery - Tuesday, March 31, 2009 - Ajax baby!
Gravatar
KaziManzurRashid - Tuesday, March 31, 2009 - What happen to your voice, I cant hear anything. BTW when you are going through the pages I can't see anything in the url, are you doing http post?
Gravatar
kike - Tuesday, March 31, 2009 - Congrats for the M!!! Subsonic it's alive and the main spanish volunteer network will be dance with it (dev site) http://beta.hacesfalta.org



Gravatar
mikekidder - Tuesday, March 31, 2009 - There is no spoon.....



looking nice, thanks for pushing the envelope and letting us enjoy the ride...
Gravatar
Rico - Tuesday, March 31, 2009 - w0w ... that's soooooo sweet Rob!
Gravatar
Rafael Izidoro - Tuesday, March 31, 2009 - amazing...
Gravatar
kriswill - Tuesday, March 31, 2009 - Hey if not talking means you can get out more hi-impact posts like this one, then I'm a fan!
Gravatar
Alex - Wednesday, April 01, 2009 - Wow!!!!!!!!
Gravatar
srulyt - Wednesday, April 01, 2009 - Cool!
Gravatar
robconery - Thursday, April 09, 2009 - Give me a week :)
Gravatar
Norman - Thursday, April 09, 2009 - Am I missing something. The link "SubSonic 3.0 pre-release" only has 2.1 releases there? It may be embedded in the MVC template but that is not very easy to work out.

Gravatar
bbqchickenrobot - Thursday, April 09, 2009 - Is this really accurate, i mean the whole asp.net MVC not having an 'M'? Don't mean to be ignorant here but wouldn't the whole Linq->SQL and the ADO.NET Entity Framework (Linq->Entities) constitute as the big 'M'? Not that subsonic shouldn't or couldn't be used as a the 'M' as well - but, technically the author of the blog post you site would be incorrect if Linq->[Insert Tech Here] is considered for the 'M' job.
Gravatar
Adam - Monday, April 13, 2009 - When I try to add my artist views, the 'View data class' drop-down doesn't contain "demo.Models.Artist" (or demo.anything...) and thus won't let me select anything from the View Content drop-down. Any idea what this could be? Thanks
Gravatar
mknopf - Tuesday, April 14, 2009 - Nice job rob, surf some good waves for me 'cause its been flat here in Florida for two weeks
Gravatar
Herding Code 43: Javier Lozano on the "M" in MVC | Herding Code - Friday, April 17, 2009 - [...] Putting the “M” Back in MVC (with SubSonic MVC Templates) [...]
Gravatar
Jon - Tuesday, April 21, 2009 - I have a SQL 2005 XML data type column in a table and be default Subsonic 3 is casting it as a string. How can I make it a XDocument or should I leave it as a string and only cast the property of my model to XDocument when needed?
Gravatar
kevinmcphail - Thursday, April 30, 2009 - Rob: Can you clarify what we need to download here? The list at the top of your post indicates we need Sub-Sonic 3.0 pre-release. In the demo you download the Subsonic MVC template. On your downloads page the Template is available but the 3.0 Pre-release is not. How do we get it? Will the scaffold tool you released that uses linq to sql dbml to build out mvc scaffold be updated to MVC 1.0? Is that tool replaced by SS 3.0 pre-release and the mvc template? Does it still support linq dbml to create scaffold? Sorry for all of the questions but I am new to subsonic and mvc and just trying to get started. I was hoping to use my current linq to sql dbml and your scaffold tool to get started without having to generate all of the repositories etc., but i am extremely confused at this point.
Gravatar
LEO - Thursday, May 28, 2009 - Great job. rob, could you please give me some advice about how to change the database from chinook to my own? Thank you
Gravatar
John - Sunday, June 07, 2009 - Clicking on the account provider does nothing, especially Yahoo, just sits there. Any solutions?
Gravatar
keithl8041 - Tuesday, June 09, 2009 - This is great - is there a MySql equivalent to the _SQLServer.tt file available yet, or is there one in the works?
Gravatar
bbqchickenrobot - Thursday, April 09, 2009 - Is this really accurate, i mean the whole asp.net MVC not having an 'M'? Don't mean to be ignorant here but wouldn't the whole Linq->SQL and the ADO.NET Entity Framework (Linq->Entities) constitute as the big 'M'? Not that subsonic shouldn't or couldn't be used as a the 'M' as well - but, technically the author of the blog post you site would be incorrect if Linq->[Insert Tech Here] is considered for the 'M' job.
Gravatar
Norman - Thursday, April 09, 2009 - Am I missing something. The link "SubSonic 3.0 pre-release" only has 2.1 releases there? It may be embedded in the MVC template but that is not very easy to work out.
Gravatar
robconery - Friday, April 10, 2009 - Give me a week :)
Gravatar
Matthew Wills - Tuesday, October 20, 2009 - The MVC template is very nice - although there is a bug in login.

If you click Google (taking you to Google login page), then click Back and then click Yahoo it will take you to the Google login page rather than the Yahoo login page.