Hello there! It looks like this might be your first time to my website. You should...
Check out ChatPast
 Read and search you
 chat history in the cloud
Subscribe to my
RSS feed
Follow @mkennedy
on Twitter.

Screencast: Building ASP.NET MVC Forms with Razor (ASP.NET MVC Foundations Series)

Monday, January 23, 2012 2:45:53 PM (Pacific Standard Time, UTC-08:00)
[note: This screencast has been adapted from my earlier blog post.]

In this ASP.NET MVC Foundations screencast, we’re going to look at building an ASP.NET MVC page which allows users to create and edit objects in our domain. We’ll cover just the basics of using HTML helpers to map model properties to our HTML form and Model Binding to convert our HTML form back into our rich domain object.

We’ll start with a very basic store website which has read-only data and we'll add the ability to create and edit products in our store. Be sure to watch in HD mode for a crisp screen.

      
Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post

Building ASP.NET MVC Forms with Razor (ASP.NET MVC Foundations Series)

Friday, January 20, 2012 12:30:04 PM (Pacific Standard Time, UTC-08:00)

[Update: Want to watch this as a screencast rather than article? Look here...]

In this ASP.NET MVC Foundations article, we’re going to look at building an ASP.NET MVC page which allows users to create and edit objects in our domain. We’ll cover just the basics of using HTML helpers to map model properties to our HTML form and Model Binding to convert our HTML form back into our rich domain object.

We’ll start with a very basic store website (downloads here: BasicMvcForms_starter.zip and BasicMvcForms_final.zip)which has a database and some basic products already listed:



Notice that we have five products. There links to edit and create products. Currently, they don’t do much:



First we’ll need to add action methods. That’s easy enough. Here’s the create code:



And similarly, the edit code:



Now that we have action methods for edit and create, we’ll need the corresponding views. Use the Visual Studio tooling to create two empty views as follows:



In the resulting dialog, choose strongly-typed with Product and an empty view without referencing the scripts (we do this globally already). In practice, you might choose “edit” and “create” to help jump-start the Razor code. In this example, we’ll do that from scratch so empty is what we want.



Now our links to edit and create products work. However they don’t have any content in their views. We’ll use the HTML Helper methods to convert our product into forms ready for the editing.

It all starts with Html.BeginForm(). We’ll define a form using this MVC convention and helper method as follows:



Next, we use the Model property of the view and the HTML helper methods to define the input fields. Note that we’re using Html.TextBoxFor() and Html.LabelFor() to create the fields. Our Featured property is a Boolean, so we’ll use Html.CheckBoxFor() on that one.



Once we flesh out the other properties, we’ll be finished with the create view. And it turns out the edit view is identical. There are tricks to share them across actions (e.g. PartialViews) but for our simple example, we’ll just copy / paste between the two views.

Last thing we need is a submit button to submit the form.



Now we should have a nice usable form to create products (or edit them if you copy & pasted that view). Here’s the edit view:



The final step is to capture the form data on the controller methods and update the database. This is where it gets interesting.

We will define a second method for each action (create & edit) which accept the post. We do not want our “show the form to start editing” code to mix with the “save the data and move on” code. We’ll achieve this separation using two attributes HttpGet & HttpPost.



Notice the original Create method has the GET attribute. This displays the form to begin creating a product. The second one is more interesting. It adds the product to the DB and returns to the product list. It also only accepts POST requests. Notice that it accepts a Product parameter which is populated using model binding by ASP.NET MVC.

Learn this pattern! It’s super common in MVC. I’ll call it the Get+Post+Redirect pattern.

1. HttpGet method shows form, returns View().
2. HttpPost method accepts the model (which is populated using model binding)
3. HttpPost method then updates the data and redirects to a new view.

Edit is similar. Often, websites use AutoMapper to do the manual copy / update you see here.



Now we have a fully functioning store (albeit a simple one). One glaring omision is validation. We’ll cover that in another post.

Conclusion

To wrap up, we took a basic MVC website and went through these steps:

- Added edit and create methods
- The new methods returned the correct model
- Added strongly-typed views for each method
- Used Html.BeginForm() and related Html.XXXXFor() methods to build out the form
- Added a submit button
- Implemented the Get+Post+Redirect pattern in edit and create.
- Took the rest of the day off. :)

Good luck with your websites and happy POSTing.

- Cheers
@mkennedy

Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post

Building a Cloud OS for .NET Developers - Part 2

Monday, June 13, 2011 11:59:43 AM (Pacific Standard Time, UTC-08:00)
In Part 1 of my Building a Cloud OS for .NET Developers series, I talked about setting up a pure cloud OS focused on developers. But the one crucial aspect I left out was the developer tools.

In this second installment, we’ll be covering exactly that. How do we manage having Visual Studio and associated tools and servers universally accessible in the cloud, even on mobile devices such as iPads?

We’ll start with the king of the cloud:

    Amazon Elastic Compute Cloud (Amazon EC2)
    http://aws.amazon.com/ec2/

At EC2 we can create a variety of Windows instances, get full admin access via remote desktop, and install anything we want (Visual Studio, SQL Server, MongoDB, etc). We can also run these for just 30 minutes here, 2 hours there and we’ll only be charge for the time we use it.

We are going to setup a Windows Server in EC2 which we can access from our Cloud OS, or any other machine or mobile device, and deck it out with all the developer tools we want. You have to choose your server type based on what you’re planning on doing as well as how much you want to pay. Here are the available options and pricing. You can roughly expect to pay $0.50/hr for a good workstation, or $0.12/hr for an acceptable but small one.
Amazon EC2 Instance Types: http://aws.amazon.com/ec2/instance-types/
Amazon EC2 Pricing: http://aws.amazon.com/ec2/pricing/
I’m currently using a Micro Instance for an SVN server which is always running as well as High-Memory Extra Large Instance for my development machine that I start and stop on-demand when I need to get some programming done. Here are the specs for the developer workstation:
High-Memory Extra Large Instance

17.1 GB of memory
6.5 EC2 Compute Units (2 virtual cores with 3.25 EC2 Compute Units each)
420 GB of instance storage
64-bit platform
I/O Performance: Moderate
API name: m2.xlarge
You have to admit, that’s a pretty killer workstation. It’s a overkill on the memory, but has better processors than the cheaper ones which also have decent memory.

The price of the dev machine is $0.69 / hour. I’ve also built some tools which help shut down the machine in case I get distracted. So far I’ve been using it pretty heavily this past few weeks and have spent probably $13 on it. That’s not bad for the possibility of being anywhere in the world (with an Internet connection) and getting my workstation running in an instant. OK, maybe it takes longer than an instant. To be fair, it usually it’s 10-15 seconds :).

Take the Free Lunch

One thing you should do straight away if you’re going to try this is sign up for the EC2 Free Tier:
AWS Free Usage Tier
http://aws.amazon.com/free/
This won’t cover the EC2 CPU time (that’s Linux only), but it will cover storage, bandwidth, S3 snapshots, etc. You also get a free Linux machine to play with if you like.

Setting up Windows in the Cloud

OK, so if you’re chosen an instance type and are ready to start, you should do the EC2 walk-through I put together here to get your machine up and running and login for the first time.
Building Windows Machines in Amazon EC2
http://www.michaelckennedy.net/blog/2010/01/31/BuildingWindowsMachinesInAmazonEC2.aspx
I’d guess that takes about 15 minutes. When you’re done, come back here...

Installing Software in EC2 and Windows

So you’ve logged in and you want to install Visual Studio, SQL Server, and other MSDN goodies. The easiest way to get them is to use the ISO DVD images from the MSDN download site. In order to mount them on your EC2 machine (which has no DVD drive), you should install
Virtual CloneDrive
http://www.slysoft.com/en/virtual-clonedrive.html
which lets you mount ISO images as if they were proper DVD drives. Then you can download and install all the MSDN files you need. A good place to start is with Visual Studio:
Microsoft Visual Studio 2010 Premium Trial - ISO
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=f81412a2-d48e-4040-9b32-27eaf771c5db&displaylang=en
One word of warning here: I’ve noticed that Chrome can freak out and fail to download very large files inside your EC2 instance. Don’t know why, but it does. So be sure to use IE or FireFox to do the downloads for the ISOs.

Syncing your Files Between your Local Machine and Dev EC2 Machine

There are two techniques we can use to sync files, depending on what category of files we’re sharing and how. For the source files, you can always setup an SVN Server (that’s what my micro instance is about). I’m a fan of Visual SVN. It’s free and easy to setup and admin.
VISUALSVN SERVER
http://www.visualsvn.com/server/
Then on your EC2 dev machine (and your others you may have) setup:
TortoiseSVN
http://tortoisesvn.net/
and
AnkhSVN for Visual Studio Integration
http://ankhsvn.open.collab.net/
Then you have super easy, reliable, and secure sharing of your source files.

    

For everything else, you can just setup a Dropbox share between your Cloud OS and you EC2 Dev Machine:


      


      

If you don’t have Dropbox and want to try it, use this link to create an account
http://db.tt/Qo7m9PA
and you’ll get me some extra free space which I always appreciate. :) Then if you have a file on your local computer you want accessible on your cloud dev machine, just drop it in your Dropbox folder on the originating computer and it’ll be there as soon as it uploads.

Waste Not, Want Not

Now here is a problem you will encounter:

You’re working on your dev machine in EC2, something comes up and you get distracted and forget about it for the rest of the day. When you come back the next day you see your EC2 system is still running and you’ve wasted $12 by leaving it running idle overnight. That sucks. If it happens on Friday, it might run the whole weekend which is even worse.

To avoid this, I wrote a little tray utility that watches for extended idle times and will shutdown your EC2 instance if it’s idle for too long.
     

Below is how you configure it. Simple, right?

    
Add it to your startup menu to make sure it starts when you log in.

     

You can download it here. I may blog about this app in greater detail later, for now feel free to use it.
Shutdown on Idle
http://www.michaelckennedy.com/Downloads/Tools/ShutdownAfterIdle.zip
Reliable Access to EC2

One annoyance in EC2 is that every time you turn off your EC2 computer, it will take on a new random public DNS name. If you really want to access to your EC2 machine from anywhere, you probably want a reliable DNS name / IP address. That’s where Elastic IPs come into play in EC2:
Feature Guide: Amazon EC2 Elastic IP Addresses
http://aws.amazon.com/articles/1346
If you create an elastic IP, then you can map it to a sub-domain in your domain and always use that. For example I could register it for cloud-developer.michaelckennedy.net. Then as long as I have a way to start my machine and re-associate the IP, all my config on my various machines (such as remembered RDP settings and passwords and such) will “stick”.

Be aware that while your EC2 machine is off, you’ll be charged a small fee (few dollars / month) for the address. You can decide whether it’s worth the trouble to save the few dollars.

Mobile / iPad Access

I’m sure when you think of accessing your EC2 dev machines, you’re thinking of doing that form Windows or maybe a Mac (using  http://www.microsoft.com/mac/remote-desktop-client). But the iPad (and even the iPhone) has apps to allow you to use Remote Desktop to EC2. For example, here’s editing the code for http://chatpast.com in Visual Studio via my iPad:


      
                                    (click for full size image)

And you can even bring up the keyboard or attach a Bluetooth keyboard.

      
                                    (click for full size image)

The app I was using is called “Jump”, and you can find it here:
Jump for iPad
http://jumpdesktop.com/
Summary

I hope that gives you some inspiration to try a new way to work in the cloud. You saw that we can create fairly serious EC2 Windows computers which can serve as developer workstations. We can share files via source control and Dropbox and we can access the computers from Windows, from Macs, and even mobile devices like an iPad.

Good luck!
@mkennedy

Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post

Building a Cloud OS for .NET Developers - Part 1

Wednesday, May 25, 2011 8:02:46 AM (Pacific Standard Time, UTC-08:00)
[Update: Read Part 2...]

Let’s talk about cloud operating systems. This article explores the options and potential of moving entirely “To The Cloud” for developers who normally demand significant offline power from their applications (IDEs, compilers, debuggers, etc). We’ll focus on .NET / Visual Studio developers, but I’m sure you can adapt this to your technology of choice.

I’ve been fascinated with what Google is doing with Chrome OS. I think finding a way to fully “live in the cloud” has a lot of promise. However, in practice Chrome OS is entirely unappealing to me. It’s just a single browser window, maximized. Yuck. I don’t mind doing most things in the browser, but I’d like multiple non-maximized browser windows and a desktop to organize things like shortcuts. That’s OK though because Chromebooks aren’t the only option. We have decent operating systems right now that can function largely in the same way if we set them up with discipline.

What we’re going to do is take a pristine Windows 7 instance and deck it out for the cloud. Even with all the choices these days, Windows 7 is still my favorite OS. I do have a Mac, several iOS devices, and I could always install Linux. Nevertheless, it’s Windows 7 for me so that’s where we’ll start.

Creating a Fresh Windows 7 Instance - Gently

I want to start from the very beginning. I don’t want old apps I’ve already installed encouraging me to “cheat” and work outside of the cloud more than necessary. At the same time I need to be able to fire up Visual Studio and do some work with an unreliable or nonexistent Internet connection So I’m keeping my current “full” Windows system intact. We’ll install a secondary instance of Windows using the awesome Boot to VHD feature in Windows 7 Ultimate. If you haven’t heard of it, I did a video walk-through here:

   Boot to VHD Screencast:
   http://www.michaelckennedy.net/blog/2009/10/20/BootToVHDScreencast.aspx

Scott Hanselman’s write up is very helpful too.

   Less Virtual, More Machine - Windows 7 and the magic of Boot to VHD:
   http://www.hanselman.com/blog/LessVirtualMoreMachineWindows7AndTheMagicOfBootToVHD.aspx

This process takes about 15 minutes. Once you’ve got everything setup, I recommend you activate and then snapshot that VHD file (from your main OS) so you can always get back to “clean”. If you’re really living the cloud lifestyle, than paving your system is much easier than before. I always keep a secondary partition around for data files anyway so that can be shared across OSes.

Now that you’ve got a truly fresh Windows 7 copy, it’s time to install just a few apps needed to set you free (and a few you’d rather not live without).

Installing “The Cloud”

While your fresh copy of Windows 7 does have IE 8 installed, that browser is entirely not up to the task of being where you spend 90% of your time. I strongly encourage you to give the latest Chrome beta a shot as your main browser. The “application shortcuts” feature of Chrome makes it much more immersive than anything IE 9 or FireFox 4 are doing (yes, I know they have pinned sites, that’s not even close).

   Chrome Beta
  
http://www.google.com/intl/en/landing/chrome/beta/

Got Chrome installed and set as your default browser? Good. Don’t forget to install all your Windows updates and Windows 7 SP1 while you’re at it.

What about Visual Studio?

You may be thinking, “I *NEED* Visual Studio 2010”. Yes, we do need it for sure, but stick with me here. We are NOT installing that beast on our fresh Windows 7 system. Remember, this is your Cloud OS. I even named mine Cloud OS in my boot loader to keep that focused in my mind.

      

We’ll talk about Visual Studio soon.

Installing Your Web Applications

You may think that you do not need to install your web apps cloud apps. There are a few installers we’ll be running such as DropBox and ChatPast, but even the plain vanilla websites such as GMail are better if you install them. That’s why Chrome is way better than the other browsers.

Let’s suppose you’ll want to use Google Docs to work with documents, presentations, Excel worksheets and so on (you will want this!). Visit https://docs.google.com, then choose “Create application shortcut” in Chrome (see image):

   

This not only gives you start menu items and desktop shortcuts, but it makes your taskbar truly useful and your web apps behave as regular Windows apps.

  

In addition, you get the true feel of your websites being applications without all the browser toolbars and other junk around it. For example, here’s how this article (barely written) looks in Google Docs right now. Notice, how it looks like an app rather than a tab buried in a busy browser. It remembers its window size and position. In short, it’s more application-like.



What Cloud Apps Should I Install?

OK, so I hope I convinced you that treating your web apps as true applications is worthwhile. Now which ones do I install? Here are a few I recommend. You may have your own favorite sites. We’ll also need a few apps that do cloudy stuff but run MSI installers on our system.

- GMail: https://mail.google.com/ (obviously :) )
- Google Docs: https://docs.google.com (good Microsoft Office replacement)
- Google Calendar: https://www.google.com/calendar/
- Google Contacts: http://mail.google.com/mail/contacts/u/0/ui/ContactManager
- 37 Signals LaunchPad: https://launchpad.37signals.com (Great web apps for projects)
- Amazon Web Service: https://console.aws.amazon.com/ec2/ (You’ll see why soon)
- Twitter: http://twitter.com/
- Office Online: http://office.live.com (for when Google docs fail you)
- Pandora: http://www.pandora.com/

Here are a few proper apps that are cloud-based in some way or another that require installers.

- Skype (obviously :) http://www.skype.com
- DropBox: https://www.dropbox.com
- ChatPast Sync Client: https://chatpast.com/

By using GMail, Google Contacts, and Google Calendar, you obviously get portability from the web. But if you have a modern phone or tablet, chances are you can keep them 100% in sync using Google’s Exchange support. I do that for both my iPhone and iPad.

There are also a couple of light-weight apps that I just didn’t want to do without and still have a solid use in a Cloud OS. I needed a good image editing app (for writing blog posts like this) and one for screen captures. So we have

- Paint.NET
: http://download.cnet.com/Paint-NET/3000-2192_4-10338146.html
- Window Clippings: http://www.windowclippings.com/

Finally, there are a couple that I use to just keep an eye on my system such as

- Process Explorer: http://technet.microsoft.com/en-us/sysinternals/bb896653

Here is the full list of *everything* I have installed on my system. Just 11 applications installed. Note that I’ve hidden some that Windows installs without asking. For example, using my Microsoft Mouse forces an install of Microsoft’s Intellipoint software when I plug it in. Similarly for the touch-pad on my laptop. To me, those don’t count so I edited them out.

   

Escape from Outlook

You may be thinking that because you still use your company’s email that you’ll need to install Microsoft Office and the 800-lbs gorilla that is Outlook. Chances are you will not need Outlook. I have several “regular” email accounts I have to check that don’t have reasonable web options.

You can setup your GMail account to automatically pull from your other email accounts as if GMail itself was a POP3 client like Outlook. Just go to Gmail > Settings >  Accounts and Import > and configure “Check mail using POP3” as well as “Send mail as”. Here you see my other accounts have recently been checked and received mail.


  

Sometimes having a “Send and Receive” button for these accounts is handy. Visit the Labs section of GMail and install the “Refresh POP accounts” add-on to make the refresh button propagate a refresh off to your other accounts as well.

  
While you are in there, you should turn on the keyboard shortcuts and take 5 minutes to learn the important ones. For example, / will take you to search, i to the inbox, e archives, <shift>-c composes an email in a separate window, etc.

Where Are the Developer Tools?

You probably didn’t see Visual Studio in that list, because it wasn’t there! In the next blog post, I’ll take you through setting up an Visual Studio 2010 instance in the cloud along with all the other developer tools and servers you might need such as SQL Server, and MongoDB, and LINQPad, and so on. Stay tuned.

When I have that post online, I’ll be sure to add a link here. If you just can’t wait, here’s a hint of where we're going next.

[Update: Read Part 2 Now]

Good luck!
@mkennedy


Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post

Getting Things Done with Backpack and 37Signals

Sunday, January 30, 2011 8:33:04 AM (Pacific Standard Time, UTC-08:00)

[Note: You can download this post as a PDF.]

Here's an article about Getting Things Done and how I use Backpack from 37Signals to make it happen.

I've recently taken on some roles where I have a lot more loose-ends in my life and adopting Getting Things Done (GTD) has really helped manage everything. I'm also a huge fan of the 37Signals suite of products (Backpack, Basecamp, etc). That should be obvious from what we're doing over at ChatPast with integrating instant messaging and 37Signals applications.

So using 37Signals to implement Getting Things Done (GTD) was the obvious choice for me. After looking at both Backpack and Basecamp, it seems that Backpack is the clear winner for implementing GTD. You'll see why shortly.

There have been some articles already written about Backpack + GTD. Brett Kelly wrote a nice one over at Getting Things Done with 37signals’ Backpack – Why I’m Switching Back. However, while this was helpful in showing me that I *could* implement GTD in Backpack, it didn't show me how to do it.

How should I organize my pages? Do I use reminders, the calendar, both or neither? There will be TODO lists, but how do I correlate them to my actual work? What about check lists? Can I have templates for repeated ones? Answering these questions is the purpose of this article.

A Step-by-step guide to implementing GTD in Backpack

In this article we'll look at the major pieces of GTD and how to fit them into Backpack.

  1. Inboxes - not just email, but all of them (there are many)
  2. Check Lists
  3. The Next Action List
  4. "Open-Loops" (Projects in GTD parlance - not to be confused with Basecamp projects)
  5. Reminders - Actions with Dates
  6. Waiting-For Lists
  7. Reference Material
  8. Taking it with you
  9. What about Basecamp?

First, A Quick Review on GTD

I'm not going to give you full summary of GTD. If you haven't started using GTD yet, I recommend that you read the book. Don't like reading? Listen to Scott Hanselman interview Lane Newsom about it or watch David Allen speak about it at Google.

Here's enough to start seeing GTD manifest itself in Backpack. First a definition, what is Getting Things Done:

GTD is a work / life management technique which encourages you to make sure you have absolutely zero open items and actions that you are tracking in your head. You get everything that you are working on or waiting for written down. This frees your mind to be fully "in the moment" and focused on what you chose to do now as well as keeps you from forgetting anything you committed to doing.

At the heart of GTD is this decision-tree model:

       
[image credit Graham King]

In our GTD in Backpack world, the 8 items ringing the workflow will mostly land in Backpack. The "Do It" one just gets done and saved nowhere - although I sometimes track these just for my personal record.

GTD in Backpack - The Basic Layout

In Backpack, I have 5 pages dedicated to GTD, which is convenient because as you see, you get 5 for free. (note: if you aren't familiar with Backpack yet, watch these short videos before going on.)

       

You can see that each page corresponded to a major component of GTD. They are further partitioned inside each page - more on that below.

1. Inboxes

With inboxes, I'm not talking about just your email inbox - although that's probably the biggest one for most people. GTD inboxes represent places that stuff that is new shows up and is waiting to be processed through the decision-tree model above.

I think you'd be surprised to see how many inboxes you truly have if you took a full account of them. GTD encourages you to do this for all sorts of things - take a full account and get them out of your mind.

That's one of the great uses of check lists in GTD + Backpack.

2. Check Lists

A check list is any set of steps you need to remember. Sometimes it's for one-off situations, others it's repeating. Processing all the new stuff in your varied inboxes is a repetitive action. So I made a check list for that. Check lists, as you can see below, are TODO lists in backpack. When they are repeated, I make a template like the actual list but with the title prefix [template]. Then I make a copy to "do" the check list each time.

Here is the check list I use several times a week to make sure that I don't forget to "process" one of my inboxes, which then feeds the other 8 types of containers ringing the workflow diagram.

       

You would see a very similar looking TODO list at the bottom of the [GTD] Check Lists page with the title '[template] Processing "in" Checklist'.

3. Next Action Lists

The Next Action Lists are pretty straight forward. As you saw above, there is a page entitled "[GTD] Next Actions". Here I track my next action for each item or project I have open. Again the page is partition internally:

       

Notice that I have a personal and business one (actually several). One rule of GTD is that if your home life is a mess, it'll affect your business life and visa versa. So manage it all here. Note also that you can add comments and attach files to the items to track additional info you might need.

If the next action came from an ongoing project (see below), then I've tried to put the name of the project as a prefix, for example House: in my personal items.

Finally, you'll see that I don't use the GTD contexts as most people might. In my world there is so much overlap for the contexts that they become meaningless. Traditional contexts might include calls, at computer, errands, at office, at home, agendas, read / review. However, I work at home with internet always on and a computer at my desk. I also do reading here. So those contexts basically all mean the same thing and thus I don't use them.

4. Projects

As you saw in the basic structure, projects get their own page (internally partitioned). Thus I have a page entitled '[GTD] Projects'. This one is pretty simple. I keep track of all the 'open-loops' that require 2 or more actions to complete. Each one gets its own TODO list within Backpack and those lists are partitioned by work and personal.

       

5. Reminders

By far, the biggest GTD "bang for the buck" that you get from Backpack come in the form of reminders. However, their effect takes some exploring to see their full potential. First, let's look at the reminders I have upcoming. Usually I have more than this, but they seem to have thinned out for the weekend.

       

In my reminders, you'll see I need to finalize the home inspection details for a house I'm buying on Feb 4th. By putting it into my reminders, I can rest assured that I'll remember it on the day that I can do something about it.

What about calendars? I make extremely heavy use of calendars for GTD. But not within Backpack. I use Google calendar, which then I sync to Outlook, my iPhone, my iPad, and I can also access via the web. If this had been an appointment, I would have skipped the reminders and just put it on my calendar. But it's an action with a date, so it goes in the reminders.

Getting Notified of Reminders

The first place to leverage reminders is to have them show up as text messages on your phone. To do this, go to "My Info" in backpack, in the section "Mobile phone reminders", check the checkbox for "Send text message reminders to my mobile phone".

Next, you'll want to see these reminders in your calendar (but not as appointments!). That's where the crazy URL starting with iCalendar: webcal://domain.backpackit.com/ical/... comes in. You can subscribe to this in Outlook or, as in my case, in Google calendar.

In my calendar, then have all these actions + dates show up alongside my day.

       

I think I had to replace 'webcal:' with 'http:' in order to add this to Google Calendar though.

6. Waiting-For Lists

Waiting lists are for situations where I know I'll need to follow up on something but no necessarily by any particular date - in that case a reminder doesn't make sense for me. But several times a week, I'll scan the list and close those loops if they other person hasn't responded by then. Here's how that looks in Backpack:

       

Note that the dates I manually typed in are not the due dates. They are the creation dates (Backpack doesn't track this). So I know how long I've been waiting.

7. Reference Material

One of the huge advantages that Basecamp has over other systems that are just simple TODO lists is the ability to attach rich reference material and additional information to the TODO item that represents a next action, or waiting item, and so on.

       

You can add comments to any TODO item. For basic information, this can be simple text. For example, if you needed to renew your insurance, you could attach the phone number and policy number to the TODO item so you don't have to look it up.

For non-textual information, you can also attach files (pictures, word docs, whatever) to the TODO item. Note that file attachments are a paid feature, so you can't use this option if you're on the free version of Backpack.

8. Taking it with you

One of the key tenants of GTD is that you should have your info with you nearly all the time. You might be thinking that using Backpack means you will only be able to get to it when you're on the web.

If you have an iPhone, iPad (or even iPod touch), you can always have an offline copy available using an app called Satchel found in the Extras section.

Here's a few screenshots from the iPhone:

Here's a few screenshots from the iPad (click to enlarge):

       
 

       
 

       

9. What about Basecamp?

Some projects are either shared by a team of people or are truly massive with many steps, artifacts, milestones, and files. These projects are better managed outside of Backpack. In that case I use the paid version of Basecamp and simply add a note to the project entry page as you can see here.

       

Conclusion

If you've been thinking of using Backpack for GTD, I hope this has given you something to work with. I certainly don't promise to be a GTD expert. But this setup works well for me and I think it will for you too.

Thanks!
@mkennedy

Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post

11 Killer Open Source Projects I Found with NuGet

Wednesday, January 19, 2011 5:18:17 PM (Pacific Standard Time, UTC-08:00)
So maybe I'm late to the party, but I recently started playing with NuGet. It's a killer new way to find, install, maintain, and manage references to open source libraries in Visual Studio 2010. Plenty of people have written about it (Phil Haack and Scott Hanselman for example). Let's just say you should learn about NuGet if you don't know it already.

What I want to talk about is all the cool open source projects I found just by flipping through the pages of the NuGet directory in the Visual Studio "Add Library Package Reference" dialog.

1. RazorEngine at http://razorengine.codeplex.com/

RazorEngine is templating engine built upon Microsoft's Razor parsing technology. The Razor Templating Engine allows you to use Razor syntax to build robust templates. No need to learn a custom clunky API for generating things like HTML and emails and so on. Just use the hot new @Razor syntax from ASP.NET MVC 3.

2. YUI Compressor for .Net at http://yuicompressor.codeplex.com/

YUI Compressor for .Net is is a .NET port of the Yahoo! UI Library's YUI Compressor Java project. Do you have a bunch of CSS and JavaScript files and you want your page to load faster. This is a great way to do it from ASP.NET.

3. 51degrees.mobi at http://51degrees.codeplex.com/

Want to build an ASP.NET MVC website that has both a desktop and mobile version from the same project? 51degrees.mobi Foundation is an ASP.NET open source module which detects mobile devices and browsers, enhancing the information available to ASP.NET. Mobile handsets can optionally be redirected to a home page designed for mobile phones. Smart phone and feature phones are all supported.

4. Lucene.Net at http://lucene.apache.org/lucene.net/

Lucene.Net is a source code, class-per-class, API-per-API and algorithmatic port of the Java Lucene search engine to the C# and .NET platform utilizing Microsoft .NET Framework. Want indexed full-text search from .NET? Here you go.

5. MvcMailer at http://www.codeproject.com/KB/aspnet/MvcMailerNuGet.aspx

Send a professional looking HTML email from your ASP.NET MVC simply by pointing at a particular view.

6. DotNetZip at http://dotnetzip.codeplex.com/

DotNetZip is an easy-to-use, FAST, FREE class library and toolset for manipulating zip files or folders. Zip and Unzip is easy: with DotNetZip, .NET applications written in VB, C# - any .NET language - can easily create, read, extract, or update zip files. For Mono or MS .NET.

7. FileDB at http://filedb.codeplex.com/

Ever wanted to have a single, simple file that you can access as a basic database without the fuss? FileDB is a free, fast, lightweight C# (v3.5) DLL project to store, retrieve and delete files using a single archive file as a container on disk. It's ideal for storing files (all kind, all sizes) without databases and keeping them organized on a single disk file.

8. Chargify.NET at http://chargify.codeplex.com/

If you need to do recurring billing, like I need to over at http://chatpast.com, then Chargify.NET is super handy. It's comprehensive C# API wrapper library for accessing http://chargify.com, using XML or JSON to read/write.

9. Facebook C# SDK at http://facebooksdk.codeplex.com/

Facebook is all the rage these days, and python, well... Here's a .NET SDK for Facebook. The Facebook C# SDK helps .Net developers build web, desktop, Silverlight, and Windows Phone 7 applications that integrate with Facebook.

10. OpenSearch Toolkit at http://opensearchtoolkit.codeplex.com/

OpenSearch is a great way to "light-up" the search features of your site. For example, if you visit http://chatpast.com with Firefox and pull down the search engine selector, you'll see "Add ChatPast Search". Do the same in Chrome and then type chatpast.com in the omnibox and hit tab then you're searching directly into your chat history (even when you're not on chatpast.com). So obviously OpenSearch is awesome. This toolkit makes that easier. The OpenSearch Toolkit provides ASP.NET developers with drop-in support for OpenSearch. This lets you quickly and easily publish valid search suggestions to all the major browsers.

11. NoRM at http://normproject.org/

LINQ, NoSQL and MongoDB, what more could you want? NoRM is how you make it happen. NoRM is a .Net library for connecting to the document-oriented database, MongoDB.

11.5. Simple MVVM for WPF, SL, and WP7 at http://simplemvvmtoolkit.codeplex.com/ (added after original post, hence the .5)

Simple MVVM Toolkit makes it easier to develop Silverlight, WPF and WP7 applications using the Model-View-ViewModel design pattern. The purpose of the toolkit is to provide a simple framework and set of tools for getting up to speed quickly with Silverlight applications based on the MVVM design pattern. The emphasis is on simplicity, but it should contain everything you need to implement MVVM for real-world line of business applications.


Keep in mind, that to get the latest version of any of these projects, you can just use the Visual Studio "Add Library Package Reference" dialog because of all the NuGet goodness. No need to download and manage these project references at a low level.

Enjoy!
@mkennedy

Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post

Portland CodeCamp Downloads: Demos and Slides

Monday, May 24, 2010 9:54:13 AM (Pacific Standard Time, UTC-08:00)

Thanks to everyone who came to my two sessions at the Portland CodeCamp this weekend.

The NoSQL Movement, LINQ, and MongoDB - Oh My!

Panel Discussion: NoSQL vs. RDBMS

You can download the slides, demo code, and the mongoctx code snippet for Visual Studio here:

NoSQL + MongoDB + LINQ:
http://www.michaelckennedy.com/Talks/Downloads/PortlandCodeCamp/Kennedy-PdxCodeCamp-2010-MongoDB-NoRM-LINQ.zip

NoSQL vs. RDBMS Panel:
http://www.michaelckennedy.com/Talks/Downloads/PortlandCodeCamp/Kennedy-PdxCodeCamp-2010-NoSQL-vs-RDBMS-Panel.zip

If you missed the sessions and want to see some MongoDB + LINQ or if you would like to recommend this session to a friend, I'll be doing a webcast on a very similar talk tomorrow:

NoSQL + MongoDB + LINQ Webcast

Finally, if you attended any of my sessions, please rate them here:

http://speakerrate.com/mkennedy

Cheers!
@mkennedy

Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post

Webcast: NoSQL Movement, LINQ, and MongoDB

Tuesday, May 11, 2010 11:37:29 AM (Pacific Standard Time, UTC-08:00)

Update: This webcast is in the past, but you can download the video and audio recordings here.

Video (WMV)
Audio (MP3)

I'm happy to announce I'll be doing a free webcast in the DevelopMentor webcast series on MongoDB, .NET, LINQ, and NoRM.

NoSQL Movement, LINQ, and MongoDB
Tuesday May 25th - 11AM PST
Register here

I hope to see you there. We'll be building out a website in ASP.NET MVC with MongoDB as the back-end using LINQ. There will be plenty of code so it should be fun and educational.

Cheers!
@mkennedy

Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post

MongoDB vs. SQL Server 2008 Performance Showdown

Thursday, April 29, 2010 10:41:30 AM (Pacific Standard Time, UTC-08:00)


This article is a follow up one I wrote last week entitled “The NoSQL Movement, LINQ, and MongoDB - Oh My!”. In that article I introduced the NoSQL movement, MongoDB, and showed you how to program against it in .NET using LINQ and NoRM.

I highlighted two cornerstone reasons why you might ditch your SQL Server for the NoSQL world of MongoDB. Those were

1. Ease-of-use and deployment
2. Performance

For ease-of-use, you’ll want to read the original article.

This article is about the performance argument for MongoDB over SQL Server (or MySql or Oracle). In the first article, I threw out a potentially controversial graph showing MongoDB performing 100 *times* better than SQL Server for inserts.

“A potentially controversial graph showing MongoDB performing 100 times better than SQL Server”

We’ll see source code, downloadable and executable examples and you can verify all of this for yourselves. But first, here’s a new twist on an old proverb:

“Data is money”

If your application is data intensive and stores lots of data, queries lots of data, and generally lives and breathes by its data, then you’d better do that efficiently or have resources (i.e. money) to burn.

Let’s imagine you’re creating a website that is for-pay and data intensive. If you were to attempt to plan out your operating costs per user to help guide the pricing of your product then the cost of storing, querying, and managing your data will likely be a significant part of that calculation.

If there is a database that is 100 times faster than SQL Server, free, easy to administer and you program it with LINQ just as you would with SQL Server then that is a very compelling choice.

When you have such a database, it means you can run your system on commodity hardware rather than high-end servers. It means you can have fewer servers to maintain and purchase or lease. It means you can charge a lot less per user of your application and get the same revenue. Think about it.

“It means you can charge a lot less per user of your application and get the same revenue. Think about it.”

One more story before we see the statistics. Kristina Chodorow from 10Gen gave a talk a few weeks ago at San Francisco’s MySQL Meetup entitled “Dropping ACID with MongoDB”. You can watch the recording here:

http://www.ustream.tv/recorded/6146875

[The audio and video isn’t too hot, but the content is. Skip the first minute without audio.]

During this talk, Kristina describes SourceForge’s experience moving from MySql to MongoDB. On MySql, SourceForge was reaching its limits of performance at its current user load. Using some of the easy scale-out options in MongoDB, they fully replaced MySQL and found MongoDB could handle the current user load easily. In fact, after some testing, they found their site can now handle 100 times the number of users it currently supports.

Not convinced of this NoSQL thing yet? Fair enough. Here are some graphs, some stats, and some code.

The scenario:

Model a data intensive web application aiming to support as many concurrent users as possible. There will be users from the web application itself. But there will also be users from an API and external applications. Users will interact with the data by having nearly as many inserts as they do queries. Their inserts are all small pieces of data and are all independent of each other.

Let me just get this out of the way and I mean the following in the nicest of ways: I don’t care about your scenario or use-case. The scenario above is what I’m trying to model. I’m not trying to do bulk-inserts or loading large files into databases or anything like that. MongoDB may be great for these. SQL Server may have specialized features around your use-case, etc. They don’t apply in my scenario. So please don’t wonder why I’m not using bulk inserts or anything like that in the examples below.

Insert Speed Comparison

It’s the inserts where the differences are most obvious between MongoDB and SQL Server.

These inserts were performed by inserting 50,000 independent objects using NoRM for MongoDB and LINQ to SQL for SQL Server 2008. Here are the data models:


MongoDB basic class


SQL Server basic class

I ran five concurrent clients hammering the databases with inserts. Here’s the screenshots for running against MongoDB and against SQL Server. Let’s zoom into the most important result with the output from one of five concurrent clients:

MongoDB:

SQL Server:

That’s right. It’s 2 seconds verses 3 1/2 minutes!

Now to be fair, this was using LINQ to SQL on the SQL side which is slow on the inserts. After discussing these results with some friends, I re-ran the tests using raw ADO.NET style programming and saw a 1.5x-3x performance improvement for SQL. That still leaves MongoDB 30x-50x faster than SQL.

Query Speed Comparison

Now let’s see about getting the data out using the same objects above on the indexed Id field for each database.

Here MongoDB still kicks some SQL butt with almost 3x performance. If we were to leverage the mad scale-out options that MongoDB affords then we could kick that up to many times more.

“If we were to leverage the mad scale-out options that MongoDB affords then we could kick that up to many times more.”

Complex Data and the Real World

Feel like that was an overly simplified example? Here’s some real world data with foreign keys and joins. Below is the complex data model.

MongoDB:

SQL Server:

It shouldn’t surprise you that MongoDB does even better here without its joins.

The Hardware

All of these tests were run on a Lenovo T61 on Windows 7 64-bit with a dual-core 2.8 GHz processor using the 64-bit versions of both SQL Server 2008 Standard and MongoDB 1.4.1. You can even see a picture of the computer here: http://twitpic.com/hywa8

Your Turn

If you want to see the entire set of data above as an Excel spreadsheet, you can download that here:

http://www.michaelckennedy.com/Downloads/sql-vs-mongo.xlsx

You can also download the sample code. Before you do, realize I haven’t done a bunch of work to make it super easy to run. But you should be able to figure it out. Just turn the knobs on the PerfConstants class for the number of inserts and queries. Then comment or uncomment sections of the code in the clients for your scenarios.

The expected use is that you’ll start the launcher application then use it to launch five concurrent clients at exactly the same time.

Download Sample:

http://www.michaelckennedy.com/Samples/SpeedOfSqlVsMongoDBAnddotNetSample.zip

Got feedback? Write a comment or contact me on Twitter: @mkennedy or find me in any of these other ways.

Thanks!

Some thanks are in order for all the help I got bouncing around ideas as well as trying different scenarios. Thanks to

Eric Cain @arcain
Jim Lehmer@dullroar
Karl Seguin @karlseguin


Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post

The NoSQL Movement, LINQ, and MongoDB - Oh My!

Thursday, April 22, 2010 1:01:01 PM (Pacific Standard Time, UTC-08:00)

Maybe you’ve heard people talking about ditching their SQL Servers and other RDBMS entirely. There is a movement out in the software development world called the "No SQL" movement and it’s taking the web application world by storm.

“Insanity!” you may cry, “for where will people put their data if not in a database? Flat files? Tell me we aren’t going back to flat files.”

No, but in the relational model, something does has to give. The NoSQL movement is about re-evaluating the constraints and scalability of data storage systems in the light of the way modern web applications generate and consume data.

The outcry about flat files above is meant to highlight an assumption developers often have about building data-driven applications: Data goes in the database (SQL Server, Oracle, or MySql). Just maybe, if we are really cutting-edge, we might consider storing our data in the cloud, but the choices generally stop there.

The NoSQL movement asks the question:

“Is the relational database (RDBMS) always the right tool for data storage and data access?”

Starting from an RDBMS is virtually an axiom of software development. However, those of us who are excited about NoSQL believe that relational databases are not always the answer. I think this highlights one of the reasons this NoSQL thing is called a movement. People are realizing they have a choice where they thought they had none.

The converse is, of course, also true. The NoSQL databases are also not always the right choice either. If you look carefully however, you will find that they are a good choice much of the time. Don’t take my word on it. Ask Facebook, Twitter, Digg, SourceForge, WebEx, Reddit and a bunch of other companies here and here that are using NoSQL databases.

This move towards NoSQL is driven by pressure from two angles in the web application world:

  • Ease-of-use and deployment
  • Performance - especially when there are many writers as compared to the number of readers (think Twitter or Facebook).

Choosing NoSQL for Ease-of-Use and Deployment

I cover the programming model in detail as well as introduce the actual database server below. For some vague motivation, let me just give you a quick look at how you define the data model and maintain it.

  1. Define your classes in C# (largely) without regard to putting them in a database. Related classes? Easy - one has a collection of the others.
  2. Create a simple DataContext-like class which exposes each top-level type that is to be stored in the database. This is only a few lines of code per collection (think of this as a table).
  3. Interact with the database using LINQ. This creates the collections (think tables), sets the schema, etc.
  4. Maintain the database and evolve it by maintaining your classes from step 1. *

Why, in the name of all that is right, do we have to model our system twice? Once in the database and once, in parallel, in code? With NoSQL, you have one place to do that - in your C# classes.

* You may have to run a transformation tool if you’re making radical data changes, but that’s true in SQL systems as well.

Choosing NoSQL for Performance

When the number of concurrent clients using your application - and thus your database - is reasonably small (let’s say 500 users as a baseline) RDBMS can work great. But what if that number grows? And if you are writing a web app, you definitely want that number to grow. At 50,000 users, can you still run on a single instance of SQL Server or MySql? How powerful does your hardware have to be to handle that? What about at 500,000 or 5,000,000 users, still good?

I’m sure there are some of you out there thinking, “What a minute now! There are plenty of systems with tons of users built upon relational databases.”

It’s true, there are. But how much expensive hardware and software do these require? How easy is it to leverage *commodity* hardware and free software? A basic SQL Server cluster might run you $100,000 just to get it up and running on decent hardware. Rather than leveraging crazy scaling-up options, the NoSQL databases let you scale-out. They make this possible (dare I say easy?) by dropping the relational aspects of a database. Some NoSQL systems such as MongoDB get even better scalability by loosening some of the durability guarantees – which they backfill somewhat with redundancy (more on MongoDB shortly).

“Ok, ok. So it’s cheaper and simpler,” you say. “How much faster than the finely tune system that is SQL Server 2008 can these open source NoSQL systems be?”

The answer is: MUCH MUCH FASTER. Here’s a simple comparison of running a bunch of concurrent inserts into SQL Server 2008 and MongoDB on the same computer.

Looks like under heavy load, I’d say it’s about 100 times faster. I’m sure there going to be tons of second guessing this graph and so on. Hold your comments please! I’ll be posting a full performance comparison with source code soon. Let me just say that I think the comparison was fair - I’ll back that up in a later post.

NoSQL and a New Programming Model

If we do not have joins and primary / foreign key relationships, how do we associate related data? In NoSQL, there is a way to mimic foreign keys for certain relationships. However the main answer is that you do not disassociate your data in the first place.

I’m sure that you’ve all heard of the object-relational impedance mismatch. A large part of that mismatch comes from the fact that we normalize the data in our database to the extreme and then use joins to reassemble that data. Not only does that cause this so-called impedance mismatch, but those joins can be really slow and they can be the death of any scale-out solution. The key to many of the NoSQL databases’ scalability is that they do not use joins. You simply save large swaths of your data as a single blob (which in MongoDB’s case, is still deeply queriable).

Shortly we’ll look at an example where we build out a disconnected, offline RSS reader that uses MongoDB and LINQ to store its data. But just think about how you might structure your data storage if you could save entire object graphs and still query them? Your "row" might be a Blog object which has an array of BlogEntries which contain the entry text, link, date, etc. Then your *entire* query to pull all the details of a single blog would hit a single “table” in the database. That might look like this query which has one result:

var blog = 
       (from b in ctx.Blogs 
       where b.Id == requestedBlogId 
       select b).FirstOrDefault();

There are no joins or anything like that because you’re saving objects not columns and those objects contain their collections already (e.g. RssEntries). There is an important distinction to make here. These NoSQL databases generally are *not* the same as object databases. They are what are known as document databases. There’s actually a big difference between the two.

Introducing MongoDB

The NoSQL database we are using in this example is MongoDB. This is free, open-source database which runs on Windows, Linux, and Mac OS X systems. You can access it from many platforms including .NET, Ruby, Java, PHP, and so on.

We’ll be using .NET and C# of course. You have several options when choosing how to access MongoDB from .NET but generally that means using LINQ and a light-weight object-mapper on top of MongoDB itself. Note that common terminology might categorize the object mapper that moves objects into and out of the database as an ORM. While that’s OK, there is technically no "R" in this ORM because MongoDB is not relational. Hence I’m calling simply an Object-Mapper (OM).

In MongoDB nomenclature, theses libraries are called drivers. My favorite .NET driver is called NoRM. It’s being actively developed and was created by Karl Seguin, Andrew Theken, Rob Conery, James Avery, and Jason Alexander. You can find NoRM on GitHub and discuss it in its related Google Group.

If you want to learn more about MongoDB you should listen to these Podcast interviews:

Michael Dirolf also has a great book in the works. You can catch a preview of it on Safari Books Online. Here’s the amazon page:

MongoDB: The Definitive Guide.

NoSQL in Action

Let’s write some code. The first step typically in a data-driven application is to spec out the database. Then we’d use LINQ to SQL or Entity Framework to generate the ORM classes. MongoDB is different. MongoDB has no schema or rather its schema is flexible and defined via usage rather than being predefined in the database. So our first step is to define the classes we’d be storing in the DB via NoRM.

We’re going to define 3 classes: Blog, RssEntry, and RssDetail. The Blog object will contain a collection of RssEntry objects. In practice you might just go with the Blog and RssEntry classes. But I wanted to model both the embedded case (Blog + RssEntry) and the loosely defined foreign key style relationship that mimic joins (RssEntry + RssDetail). That way we can demonstrate both use-cases.

Here’s a taste of the Blog class:

public class Blog
{
	public ObjectId _id { get; set; }
	public string Name { get; set; }
	public string Url { get; set; }
	public string RssUrl { get; set; }
	public List<RssEntry> Entries { get; set; }
      // ...
}

Notice that it contains a collection (List<T> really) of RssEntry objects. That’s the relationship supported by nesting. The Blog class just has this collection as part of its data model.

The RssEntry class has the summary info for a blog entry:

public class RssEntry
{
	public ObjectId _id { get; set; }
		
	public Guid UniqueId { get; set; }
	public DateTime PostedDate { get; set; }
	public string Title { get; set; }
	public string RssGuid { get; set; }
}

And the larger data is stored in the RssDetails class (for example the text of the post):

public class RssDetails
{
	public ObjectId _id { get; set; }

	// this is kinda like the foreign key.
	public Guid RssEntryId { get; set; }

	public List<string> Categories { get; set; }
	public string Link { get; set; }
	public string Text { get; set; }
	// ...
}

Let’s see how we insert an entire set of Blog data into the database. We begin by generating the objects (Blog, RssEntry, etc) in memory and then serializing them via NoRM to MongoDB much as you would in LINQ to SQL. The difference is this will actually generate the collections (analogous to tables) if they don’t already exist and it will define the implicit schema to match our objects:

void SaveBlogToMongoDb(
	string rssUrl, XElement root, RssDataContext ctx)
{
	Blog blog = new Blog();
	blog.RssUrl = rssUrl;
	blog.Name = GetBlogName(root);
	blog.Url = GetBlogUrl(root);

	blog.Entries = ParseEntries(root);
	IEnumerable<RssDetails> details 
		= GetDetails(blog.Entries, root);
			
	foreach (RssDetails detail in details)
	{
		ctx.Add(detail);
	}

	ctx.Add(blog);
}

Here we are using a class called RssDataContext which we wrote manually. It is very similar to what LINQ to SQL and Entity Framework use to do the object-relational mapping. Want to do a query? Do you know LINQ? Well then you’re all set:

var results = 
    from b in ctx.Blog 
    where b.Name.Contains( "MongoDB" ) 
    select b;

How do you add a new entry to an existing blog and update it in the database?

void AddEntry(Blog blog, RssEntry entry)
{
	blog.Entries.Add(entry);
	ctx.Save(blog);
}

We leverage the fact that the blog.Entries collection is a List and just add to it. Then save will update the record in the DB.

All this works great and is highly performant. But do be careful as not all the LINQ operations are fully implemented yet in NoRM and some (like join) may never be added because MongoDB doesn’t support it.

To get started, download MongoDB the tools and server here:

http://www.mongodb.org

You unzip the zip file and run the mongod.exe program. Be sure that you have created the C:\data\db folder. It appears at first that you have to run MongoDB in a console window. But you can register it as a Windows Service:

Here’s some helpful advice on installing MongoDB as a Windows Service (there is a small bug you have to work around):

http://www.deltasdevelopers.com/post/Running-MongoDB-as-a-Windows-Service.aspx

There’s also a management console (and I mean "console"):

It’s a little different. You’ll get used to it. The means of interaction with the server is through JavaScript rather than T-SQL and the storage format is a binary form of JSON as you can see.

For a project I’m working on I’ve built a Windows Forms UI that lets me manage the database easily by just adding an object data source and doing some drag-drop magic in Visual Studio. Generally I look down upon that sort of development, but for an admin tool it’s just fine.

Now It’s Your Turn!

Try it out for yourself. Download MongoDB and the NoRM driver and build some apps. You may also want to check out the source code for my demo app:

Download Sample: RssMongoSample-Kennedy.zip

Got feedback? Write a comment or contact me on Twitter where I'm @mkennedy or find me in any of these other ways.

Recommended Reading:

Here are some other blogs on this subject.


 
Tweet this Follow me on Twitter Post this to dotnetshoutout.com Digg this Submit this to Stumbleupon email this post