Home > C#, MemoDb > Introduction to MemoDb

Introduction to MemoDb

I’m working on an internal framework on the company I work (it will be open source soon I expect to post a lot in the future about it) that needs the ability of mocking a repository with a memory database. Since this repository works with Linq, an implementation with a List inside was enough.
The time passed and we realize that it will be really usefull to have transactions in that repository (ok, not so usefull, but at least funny 🙂 ). So I started to work on MemoDb.
The source code of the first version is in http://memodb.codeplex.com.

Let’s show some examples:

var memo = new Memo()
				.Map<City>();


using (var s = memo.CreateSession())
{
	s.Insert(new City
				 {
					 Id = 1,
					 Name = "Buenos Aires"
				 });
	s.Insert(new City
				 {
					 Id = 2,
					 Name = "New York"
				 });
	s.Insert(new City
				 {
					 Id = 3,
					 Name = "Montevideo"
				 });
	s.Insert(new City
				 {
					 Id = 4,
					 Name = "Bogotá"
				 });
	s.Flush();
	s.Insert(new City
				 {
					 Id = 5,
					 Name = "Bangkok"
				 });

}

using (var s = memo.CreateSession())
{
	var cities = s.Query<City>().Where(x => x.Name.StartsWith("B"));

	Assert.AreEqual(2, cities.Count());
}

Note that it doesn’t store Bankgok.

var memo = new Memo()
				.Map<City>();

var buenosAires = new City
{
	Id = 1,
	Name = "Buenos Aires"
};
using (var s = memo.CreateSession())
{
	s.Insert(buenosAires);
	s.Flush();
}

City buenosAires2;

using (var s = memo.CreateSession())
{
	var test = s.GetById<City>(buenosAires.Id);
	test.Name = "Bs As"; //Not flushed!
}

using (var s = memo.CreateSession())
{
	buenosAires2 = s.GetById<City>(buenosAires.Id);
}

Assert.AreEqual("Buenos Aires", buenosAires2.Name);

Right now it supports:

  • Inserts
  • Updates of dirty objects
  • Many-to-one relationships
  • Queries

Next steps:

  • Delete
  • Collection management
  • Id generation strategies
  • Cascade

In future posts I will be talking about the implementation details.

Advertisements
Categories: C#, MemoDb Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: