NoSQL: Eloquera and ASP.NET MVC 3 (and Ninject)

I thought today I’d give Eloquera a swing, just to do something fun and new before starting the other obligations of the day. Eloquera is another objected oriented database, like Db4o or MongoDb. The difference is that Eloquera is natively .NET and it’s free whereas db4o is not. But I honestly do not prefer the one above the other. I’m just trying things out.

I wrote a quick web application as a POC.

First, download Eloquera from here. I took the x64 .NET 4.0 version and installed it..
I edited the C:\Program Files\Eloquera\Eloquera Server 3.0\Eloquera.config file so that the Eloquera files are in c:\temp\db by adding DatabasePath=”c:\temp\db”:

[code language=”xml”]
<Server ServerPort="43962"
DatabasePath="c:\temp\db"
Trace="true"
InMemoryAllowed="true"
Secure="true"
AllowUsers=""
AllowGroups="Everyone" />
<SmartRuntime Smart="true" />
[/code]

Oh and don’t forget to take a look in the Samples directory in the program folder.

Then I created an new ASP.NET MVC 3 application and edited the Global.asax.cs. Here is the relevant portion:

Here are the gotcha’s:

  • The OpenSession() method opens the database and if it doesn’t exist, a new one is created with some dummy data.
  • I use the session-per-web request pattern (the lifetime of a session is the same as a web request). You can see that here in the complete Global.asax.cs.
  • I do not have to deal with Transactions with Eloquera.
  • I have to register types explicitly, else the Views won’t recognize them: db.RegisterType(typeof(iSay.Story));

And then I only have to get the current session in my Repositories with (private DB db = MvcApplication.db;) and I’m good to go just like any other app!

[code lang=”csharp”]
using Eloquera.Client;

namespace iSay.Infrastructure
{
public class StoryRepository : IStoryRepository
{
private DB db = MvcApplication.db;
public IEnumerable<Story> getStories()
{
return db.ExecuteQuery("SELECT Story").OfType<Story>();
}

public void Add(Story s)
{
db.Store(s);
}

public int getNumberOfComments(Story s)
{
var comments = s.Comments.Count();
return comments;
}
}
}
[/code]

The controller (I used Ninject again, as you can see I injected the controller with IStoryRepository):

[code lang=”csharp”]
using iSay.Infrastructure;

namespace iSay.Controllers
{
public class HomeController : Controller
{
private IStoryRepository _repo;

public HomeController(IStoryRepository repo)
{
_repo = repo;
}

public ActionResult Index()
{
var stories = _repo.getStories();
return View(stories);
}

}
}
[/code]

Hmm, that’s almost embarrassing, as easy as this is.

You can view the source code here. Maybe I’ll spice it up later but I have to go now.

Itslet is celebrating it’s first birthday!

8 december 2010 – Today it’s our first birthday, 1 year of Itslet.

{
public class Party : Birthday
{
public string Celebration { get; set; }
public string Cake { get; set; }
public string Cheer { get; set; }
public DateTime? ValidFrom { get; set; }
}
}

Thanks to everyone out there supporting and encouraging us.

Now everybody sing a long with this great party song: