Raven DB
Raven DB is an opensource ‘document database’, it can be used to store documents.
Url: http://ravendb.net/
1] Installing
On the download page there is a zip file available, but the cool new way is to search in NuGet. So create a Visual Studio project –> Add library package reference and search for RavenDb:
Hit Install and accept license:
2] Start database
In the package folder ‘RavenDB.1.0.0.322\Server’ there is an executable ‘Raven.Server.exe’, run it.
If you enter http://localhost:8080 a Silverlight management console turns up.
3] Coding Hello World
Create two orders, a product list and store it.
class Program
{
static void Main(string[] args)
{
string url="http://localhost:8080";
var store = new DocumentStore { Url = url };
store.Initialize();
using (var session = store.OpenSession())
{
var product1 = new Product{Cost = 3.99m,Name = "Koffie"};
var product2 = new Product{Cost = 3m,Name = "Soep"};
var order = new Order();
order.Products.Add(product1);
order.Products.Add(product2);
session.Store(order);
session.SaveChanges();
}
}
public class Product
{
public string Id { get; set; }
public string Name { get; set; }
public decimal Cost { get; set; }
}
public class Order
{
public string Id { get; set; }
public string Customer { get; set; }
public IList<Product> Products { get; set; }
public Order()
{
Products = new List<Product>();
}
}
}
When you run the application, a file ‘Data’ is generated.
4] View the database on http://localhost:8080 and search for the just inserted order:
Or type http://localhost:8080/docs/orders/1025 in a browser and get the json back.
5] Query data
With a simple query the data can be retrieved:
var orders=session.Query<Order>().ToList();
In a future post the Raven DB spatial options will be explored.
No comments yet.
Leave a Reply
-
Archives
- November 2011 (1)
- October 2011 (1)
- September 2011 (1)
- May 2011 (3)
- March 2008 (4)
-
Categories
-
RSS
Entries RSS
Comments RSS