Hanalei, Hawaii Tuesday, February 09, 2010

Putting the “M” Back in MVC

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.

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)


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

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

Also, lots of brazilian artists in your database :)
jchannon - April 8, 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.
jchannon - April 3, 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!
robconery - April 3, 2009 - Hmm - could be. Can you log it for me here:

http://code.google.com/p/subsonicthree/issues/list
jchannon - April 3, 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
adolfojp - April 2, 2009 - I tried this and now I can create a new Artist without specifying a name. It broke the entire validation.
adolfojp - April 2, 2009 - He is actually Rob Zombie.
Johan - April 2, 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.
adolfojp - April 2, 2009 - I am getting the same error.
adolfojp - April 2, 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
robconery - April 2, 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.
Johan - April 2, 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).
adolfojp - April 2, 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.



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

Does this work with MySql?
Bill - April 1, 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.
Bill - April 1, 2009 - Yes I do and using VS2008
robconery - April 1, 2009 - Do you have MVC 1.0 installed?
Bill - April 1, 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
jchannon - April 1, 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
jchannon - April 1, 2009 - Ignore me..
jchannon - April 1, 2009 - Impressive dude!



What version of Subsonic does this video use?

robconery - 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.
robconery - March 31, 2009 - Probably - not quite sure how to do that just yet :)
rocklau - March 31, 2009 - rob,

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

jongalloway - 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?
GregRoberts - 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.
robconery - 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...
William - 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?
dale - March 31, 2009 - Kind of like the RoR screencasts. But with balls thanx to Rob Zombie audio.



Excellent demo
kevintechie - March 31, 2009 - Dude, YOU'RE the zombie!
Nathan - March 31, 2009 - Loved it! Might have some ammo for the guys at work. ;)
Joe Chung - March 31, 2009 - Rock on, Rob! Nice video!
Ben - March 31, 2009 - That's impressive. I considered using subsonic and asp.net mvc. Now I know I have to try it.
educobuci - 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!
robconery - March 31, 2009 - Hrrmph. Was it dead ? :p
Tom L - March 31, 2009 - Very nice Rob. Glad to see you using the post MVC downtime to revive this project.



Also nice touch on Dragula
Chad Moran - 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.
Nathan Totten - March 31, 2009 - Awesome! I will definitely be using this soon.
PabloBlamirez - March 31, 2009 - Awsum sauce :-)
EricTN - March 31, 2009 - Subsonic brings the "M", template makes it fly

Conery's done it again, MVC won't die...
Eric Hexter - March 31, 2009 - good stuff.. nice to see someone putting together some low-friction solutions!
robconery - March 31, 2009 - Ajax baby!
KaziManzurRashid - 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?
kike - 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



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



looking nice, thanks for pushing the envelope and letting us enjoy the ride...
Rico - March 31, 2009 - w0w ... that's soooooo sweet Rob!
Rafael Izidoro - March 31, 2009 - amazing...
kriswill - March 31, 2009 - Hey if not talking means you can get out more hi-impact posts like this one, then I'm a fan!
Alex - April 1, 2009 - Wow!!!!!!!!
srulyt - April 1, 2009 - Cool!
robconery - April 9, 2009 - Give me a week :)
Norman - April 9, 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.

bbqchickenrobot - April 9, 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.
Adam - 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
mknopf - April 14, 2009 - Nice job rob, surf some good waves for me 'cause its been flat here in Florida for two weeks
Herding Code 43: Javier Lozano on the "M" in MVC | Herding Code - April 17, 2009 - [...] Putting the “M” Back in MVC (with SubSonic MVC Templates) [...]
Jon - 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?
robconery - April 21, 2009 - Use a partial class and expose an XDocument property which consumes the string
kevinmcphail - 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.
robconery - April 30, 2009 - Everything you need is in the download :)
LEO - 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
John - June 7, 2009 - Clicking on the account provider does nothing, especially Yahoo, just sits there. Any solutions?
keithl8041 - June 9, 2009 - This is great - is there a MySql equivalent to the _SQLServer.tt file available yet, or is there one in the works?
bbqchickenrobot - April 9, 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.
Norman - April 9, 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.
robconery - April 10, 2009 - Give me a week :)
jimi - October 17, 2009 - Hi there,

Would it be possible for you to reply to this message with a download link for your new implementation re the seperate files??

this would be really useful.

thanks

jimi
jimi - October 20, 2009 - it's ok, i figured it out with the t4 toolkit ;)
Matthew Wills - 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.
Gecko