A couple of weeks ago I was asked to develop a mobile application with data access in ASP.NET.
Naturally, I did a bit of research, tried out a few things, and finally came to the conclusion that .NET framework 4.0 was the best choice.
So I got down straight to development, using Jquery Mobile Framework, ASP.NET with .NET 4.0, MVC3, ADO.NET Entity Framework 4.1, and ASPX (web forms).
It was easy enough to set up, but when it came down to implementing user controls, I found it a nightmare. Passing parameters to the user control whilst using a MultiView was giving me a headache.
The issue here is that web forms are not naturally set up to work via AJAX calls, and Jquery Mobile Framework relies entirely on AJAX calls. So I decided to try out the Razor layout engine instead of web forms.
I had no experience using the Razor layout engine, but after a couple of hours, I found it delicious to use. I could code up pages much faster than in web forms. And the integration with controllers and models in the MVC3 framework was just, natural, it all fit into place beautifully.
Naturally, I found a few issues learning the basics of the MVC3 framework, forms authentication, the Razor layout engine, and accessing data from a database. Tutorials seemed to be all over the place, but I came across a few good ones which I will share with you.
If you are getting started with MVC3 + Razor + Data access (using DBContext in MVC3), follow these tutorials, and you’ll be a ‘pro’ in a couple of days (providing you have enough experience).
Learn the basics of the Razor layout syntax:
http://msdn.microsoft.com/en-us/gg618477
Learn how “sections” work in Razor:
http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx
Learn how to implement partial views in Razor (which can be used as ‘user controls’):
http://rachelappel.com/razor/partial-views-in-asp-net-mvc-3-w-the-razor-view-engine/
Learn how a basic MVC3 application works in .NET:
http://www.asp.net/mvc/tutorials/creating-a-mvc-3-application-with-razor-and-unobtrusive-javascript
Learn how to integrate data access (database first) using MVC3 and EF 4.1:
http://msdn.microsoft.com/en-us/data/gg685489
(If you want to create models, but use a MSSQL database that is not on your machine, and you don’t want to have it in the App_Data folder, just follow the steps, then delete the database from the app_data folder, and change the data source in the web.config to point to the correct location).
Writing your own queries to access the database instead of relying solely on those from the model:
So that’s it for now, I thought it would be good to have a central location for these tutorials as they served me well whilst I learned the basics of MVC3 + EF4.1 + Razor, so I hope they are useful to you as well.
If you have any queries, please let me know in the comment section below.
A random thought popped into my head not so long ago: What if we had a universal language that integrated all the common programming language syntaxes, integrating the binaries, engines and function calls for each of them, allowing anything to be written in any language in each file?
.NET made huge progress allowing a single project to be coded with different languages, at file-level of course. But what if we could use several languages in a single file?
I know this would probably represent a heavy strain on the processing part of it, but for web-based technologies it would be an interesting approach. Just imagine, Rails+PHP+Python+Java, a world where we can truly live together. Or not?
Take the following code as an example:
cout << "Hello world" << endl;
echo "This is a test";
System.Windows.MessageBox("And another test");
print "Just for the sake of it"
Assuming you can keep it clean, and standards are adopted, I think it would be great. Things might be simpler in certain languages than in others, and sometimes it would certainly be reflected in the amount of lines as many languages implement built-in functions that perform many tasks with a single line of code.
On the other hand, it could become programming hell, but I’d be interested if such a thing existed, for the mere purpose of having fun. What do you think? Would it be “programming hell”? or does it actually sound viable?
I’ve been creating and modifying a few stored procedures for a ‘debt history and future payments’ report in a VS.NET app using SQL Server 2005 for the past days. Quite a bit of a task to be honest, but I have found something very useful while developing large stored procedures. Some times they can get out of hand, you know, with virtual tables, views, massive calculations involving aggregate functions and loads of inner joins.
Document everything! Changes, current status, this way you’ll have a clue on where you stand and what you must achieve, so even if things get out of hand this is always a good reference, and gives you a great focus. It’s also a very good guide when you finished it, and several months later your customer calls you nagging that it’s not working anymore. You go back, read all you wrote, and get a full view on it’s current status and what you must do to correct the mistakes.
An example of my style of documenting stored procedures is as follows:
This was one of the first games I ever finished… it’s terrible, it barely works, it flickers a hell of a lot (I used VB4 without BitBlt), it has a bad plot and theme, it is boring as hell, but it brings back a few memories
*sniff*.
If you’ve got time on your hands and want to check it out go to the following URL, the download is available on the main page: http://www.citiria.com/mb/
I think the major achievement I had making this game was learning TCP/IP packet transmission. The game was supposedly multiplayer, I never really tested it out thoroughly though. Give it a try and tell me what you think
(I might release the source code for it one of these days, as soon as I find it heheh).
* Update: Removed the game from the website because I had to reorganize quite a few things, if you are interested in it just email me.
When building your website, I’d suggest to ease out on flash. Maybe in a few years, when regular bandwidth is at 6MBPS and higher it would be acceptable, but today most users still have 1MBPS and lower. It takes too long to load flash sites built 100% with flash.
Example: http://www.microsoft.com/forefront/easyeasier/index.htm#intro
Please reconsider building a website 100% with flash, it’s much better to opt for a nice flash intro, and use it in various parts, sidebars, etc. You optimize speed and experience that way. Just a tip