I originally started blogging to keep track of code snippets and specific things that I thought I would forget in the future. Well, in the past several months I haven’t worked on any hardcore projects, so I haven’t had any hardcore blog posts. Now though, I have dug in and this next set of blog posts are going to pretty technical.
So, as we all know there are a few pieces of the .NET landscape that have changed in the last few years first with VS2008 + .NET 3.5, and then especially with VS2010 and .NET 4.0. I’ve dug into these new technologies and wanted to write about what I learned during the learning curve. How you might approach writing a website, has fundamentally changed, in 3 very different ways:
This is object-relational mapping (ORM) functionality that is built into .NET. It let’s you point to a database, and it generates a bunch of mapped data structures that represent your tables or stored procedures. Most importantly though is that it understands and respects foreign-key constraints, and let’s you access related tables through properties in your data structures. I’ll go into this in more detail, but for now just understand that it’s a very different, but extremely powerful way to interact with your underlying data in a strongly-typed way using collections of objects (like Customer and Order) instead of generic DataSets and DataTables of just “data”.
Linq and specifically Linq To Entities:
Language Integrated Query (Linq) is a new “language”, or set of commands you can use right inside of your favorite .NET language to query various objects that store data. I know that sounds a bit vague, but the point is that Linq can query from all sorts of objects. However, when you couple Linq with your Entity Framework setup – it makes interacting with your data structures that much easier. In fact, you will giggle at how powerful these features are – you can do so much with just a little clever coding.
MVC and MVVM:
Model View Controller (MVC) and Model View View-Model (MVVM) are fundamentally different ways to approach writing a web site. Instead of creating an .aspx page and putting content on it, there is a clear separation between routing a URL request (the controller), getting and massaging the data (Model and View-Model), and presenting on the screen (View). There is definitely a learning curve here, but after having used this for a bit – it really is better in every way.
In fact, I am nothing short of blown-away at how easy and powerfully these technologies work together. If you are brand new to these ideas, I am starting from scratch so this should be a good primer.
For me to learn new things, I really do best if I have a practical project. In this case, I can always seem to turn to my brothers business! I originally wrote an MS Access database for them to keep track of quotes and orders and things, which they’ve been using. The database is proper and has referential integrity.
Well, we want to put that Access database into a SQL server, put a web front-end in front it, later support phone access to the website (having a phone-friendly version, I mean) – and then there may be some need to have a fat-client that talks over the internet to the database as well.
I feel I’m about 2/3 of the way through the learning curve, and a lot has already happened and a LOT has been learned. So, I wanted to stop development and write this stuff down before I forget. Here’s what I plan to do for blog posts, to explain how to get from Point A “I know regular ASP.NET and SQL” to Point B “I know EF, how to use Linq to query it, and how to use MVC to show it”: