In my continuing series on NoSQL Databases I have been mainly describing some of the concepts behind NoSQL (and in particular Document) Databases.  In this post I will start to dive into some code.

As mentioned earlier I will be using RavenDB as this is a .NET friendly database.

In this first example lets create a simple ASP.NET MVC 3 Application that uses RavenDB as its data source.

I will start with a simple “My Tasks” Application which I created by using the Internet Application template in ASP.NET MVC 3.  Next I created a simple Task model class (Listing 1).

Listing 1: The Task class
    public class Task
    {
        public int TaskId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public bool IsComplete { get; set; }
    }
 

I then used the Scaffolding available in ASP.NET MVC 3 to create a TaskController (Figure 1), as well as the Entity Framework DataContext class and all the Razor Views necessary for CRUD operations.

Figure 1: Scaffold a new TaskController class
image

And finally I created a SQL Server Compact Edition Database to store the data and a Tasks table with columns that matched the names and types of the Task class’s properties.

To prove that everything was wired up correctly I browsed to the application and added some data (Figure 2).

Figure 2: A List of Tasks
image

But the goal of this application is to use RavenDB as the database, not to create an EF Code First/SQL CE application.

As I mentioned in the 3rd post in this series, RavenDB can be configured in three different ways.  I am going to use the embedded mode.  Luckily, RavenDB is available as a NuGet package.  To add a NuGet package to a Visual Studio project we can right-click on the References folder (Figure 3).

Figure 3: Add a new Nuget package
image

and select “Manage NuGet Packages”.  In the Package Manager window enter Raven  in the search box and install the RavenDB (Embedded) package (Figure 4).

Figure 4: Install RavenDB using NuGet
image

The installation adds quite a few assemblies to the bin folder.

Next we need to configure Raven, so we will create a Folder in the App_Data folder call “Database” (Figure 5),

Figure 5: Create a new Database Folder for the RavenDB database
image

and we will modify the connection string that RavenDB added to the web.config to point to the folder we just created.

Listing 2: Update connection string in web.config
  <connectionStrings>
    <add name="RavenDB " connectionString="DataDir = ~\App_Data\Database" />
  </connectionStrings>
 

So now we are all set up ready to convert our application to use RavenDB, and in the next post I will show how to hook up the existing TaskController class, so we can store our tasks in an embedded RavenDB database instead of a SQL Compact database.


Posted in: Data , ASP.NET  Tags: , , ,

Comments


November 17. 2011 13:43
Lindsay
Dear Max,

My name is Lindsay Gordon, and I'm the Community Manager at DZone.com, a social linking and blogging network for developers (I see you've heard of us!).  One of our content curators discovered your blog, and he suggested that I contact you.  I wanted to let you know about our program for quality bloggers like yourself.  It is called the Most Valuable Blogger (MVB) program, and we'd like to invite you to join if you are interested.  We have a page that describes the program and lists the benefits you would receive here: www.dzone.com/aboutmvb

We currently have over 350 MVBs, and most of them say that they definitely notice an increase in traffic because of our links back to original postings and the SEO benefits that entails.  Our featuring bloggers such as you also gives writers a chance to be read by a much wider audience, increasing the opportunities for engagement in conversation and recognition from all kinds of people.  We even have some 'big name' MVBs including Ted Neward, Martin Fowler, and Ben Forta.  It's pretty simple to join, you just fill out a one page consent form and that's it!  Send me an email and let me know what you think.

Here are 4 MVB repost examples:
http://agile.dzone.com/news/flag-argument
java.dzone.com/.../primary-key-lookups-are-28x
java.dzone.com/news/storing-and-querying-rdf-data
java.dzone.com/.../scalas-parallel-collections

We just launched a new NoSQL zone and your writing would be fantastic for it!  Also, one of our MVBs is the creator of RavenDB.  We'd be glad to connect you two!

I hope that gives you a good sense of the program.  Let me know if you have any questions or alternative ideas for exposing your content to our audience.

Best regards,
Lindsay Gordon
DZone Community Manager
919-400-4109
lgordon@dzone.com


November 17. 2011 14:08
Lindsay
Oh dear, my apologies--I definitely meant to write "Dear Charles."  I contact many potential MVBs a week, so I go through a lot of names.  I hope that my faux pas doesn't discourage you from joining the DZone MVB team!

--Lindsay  


November 26. 2011 15:03
security toronto
Hey , thank you for discussing this topic on this website. I wound up inside your blog right after researching physical fitness connected issues on Yahoo… guess I lost track of what I had been performing! Anyway I’ll be back once again within the long run to check out your blog posts down the road.


November 27. 2011 01:17
cheap nokia mobile phones
Comparing with other website, I conjectured that UK based mobile phone shopping would be very helpful for all because it website cheap mobile phone deals on orange, 02, and Vodafone.


December 11. 2011 12:02
fitness workouts
Great job on featuring actually certainly one of one of the critical sophisticated blogs Ive arrive across in a while! Its basically wonderful how a lot you’ll have the ability to think about away from a factor mainly merely due to how aesthetically marvelous it is. Youve place jointly an amazing blog site space -great graphics, films, layout. That is certainly a must-see web site!

 Search Blog

 Calendar

«  February 2012  »
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011
View posts in large calendar

 Tags

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012 Thoughts from the Wet Coast