So you are sitting in one of those interminable tuesday morning meetings at work, trying not to spill your now-cold coffee, wondering if the cryptic doodling on your pad suggests anything about your state of mind, when the project manager says ‘..and I’m sure Nick could convert the database into a fully functional Asp.Net Mvc application, so that we can manage the data in a more user friendly and secure manner. How long do you think that would take, Nick?’.
And now everyone turns to look at you.
Scrambling to figure out what the context is and how the conversation has turned to this, you pluck a hopefully reasonable figure out of the air. ‘Yeah, should be able to turn that around in a couple of weeks..’ you say brightly.
‘Excellent’ says the project manager, ‘I knew i could depend on you’. Everyone smiles in relief, and the meeting then proceeds to plan the complex multi-team delivery of downstream modules, all of it dependent on your proposed timescale.
As you all file out of meeting room 7c, the project manager says ‘..oh by the way, i believe its an Oracle database that we need converting to the Mvc app, and we’ll be needing it to use WebApi, and Asp.Net Identity for secure authentication etc, that’s not going to be a problem is it?’
‘Um..’ you say.
Back at your desk, you are wondering if anyone has ever undertaken to build an asp.net mvc app on an Oracle database, doesn’t sound very likely. How on earth are you going to get off the ground with this, and deploy in 2 weeks?
Let me show you how to do it in 5 minutes.
[You will need Visual Studio (2012+) and the CodeTrigger For Visual Studio extension (Full Trial, or Professional Version, v184.108.40.206+), Windows 7.1+, .Net Framework 4.6.1+. Once you got that setup, make a note of the time and begin]
Step 1. Start a new CodeTrigger project within Visual Studio, give it a name, and select the ‘DB to Multi-tier Mvc ..’ wizard. Click next.
Step 2. Select your data source type, and configure the connection settings. Click ‘Connect’ to verify the settings, and click ‘Create’.
Step 3. Voila, the multi-tier Visual Studio project is generated and pre-built. (If you don’t have nuget automatic package download enabled, you may have missing package build errors at this stage, in this case, enable nuget automatic package download on your solution, or otherwise download the missing asp.net core packages from nuget, and rebuild. If you do have nuget automatic package download enabled then this is all done for you).
Note that this wizard will attempt to automatically create the identity tables required by Asp.Net identity, in your database. If those tables already exist then they will not be regenerated.
In the ‘Schema Objects’ tab, select any tables you want to be represented in the final application. If you have 15 tables or less, you might as well click the ‘Select all’ checkbox.
Step 4. Click on the ‘Business Objects’ tab. The business model is generated from your previous selections and all related business model entities are displayed for your selection, along with their relationships. Again, if the number of model entities is about 15 or less, you may as well select all, otherwise choose judiciously according to your project needs.
Step 5. Shoot! Click the red button to generate the selected code classes. Stand back and be happy as CodeTrigger spews out several thousand lines of required code in a matter of seconds! At this point the project/solution will build itself and report happy. If there’s any outstanding tasks, they might be reported in the ‘Things to do’ tab but I find that useful only when I’ve changed some of the default automatic code generation settings (like automatic sql scripting or automatic project file update).
Step 6. Hit F5 to build and run. At this point (or soon after) when I’m building an Oracle based MVC app (as opposed to Sql Server or MySQL), I sometimes find that the solution fails with an unhandled Oracle client Exception. This seems to be because Oracle is still in shock about what just happened. If this occurs I close Visual Studio and re-open it, and that seems to cure the issue once and for all.
Enjoy the sight of your fully functioning Asp.Net Mvc App. Login using an auto generated login for debug purposes (Username: Admin@example.com Password: Admin@123456).
Once logged in, click on the ‘Sample Pages’ link to view/update your various entities.
Step 7. Check the time. 5 minutes! Project manager is still writing up his minutes from the meeting, and you’re already done. What are you going to do with the remaining 13 days, 11 hours and 55 minutes? Well you can get a fresh hot coffee from Inca Beans (no, don’t warm up your old one in the microwave), and sit back. Now if only someone would write a tool that did all the unit, system and integration testing in 5 minutes, you could be home for lunch.
Edit 29th June 2016: For a version of this approach which enables unit-testing by using the mockable repository pattern, see Database to Testable WebApi MVC app in 15 mins