SisoDb – Getting started

I think it’s high time for providing you with a simple example of how SisoDb (http://www.sisodb.com) can be put to work.

Download the source or the binaries from https://github.com/danielwertheim/SisoDb-Provider. The time of this writings, the version is v0.7.0.1.

In this simple example I will not have a GUI. I will actually use tests instead, and I will use NUnit as my testing framework. The scenarios below will only deal with the data storage strategy and not the business scenario, hence no validation etc.

Register a new customer

Fairly simple. We want to store some simple information about a customer. E.g: CustomerNo, First name, Last name, Shipping address and Billing address.

[Test]
public void RegisterNewCustomer()
{
    var customer = new Customer
    {
        CustomerNo = "Super100",
        Firstname = "Daniel",
        Lastname = "Wertheim",
        BillingAddress =
            new Address
            {
                Street = "The street 1", Zip = "12345", 
                City = "The City", Country = "Sweden"
            }
    };

    //TODO: Connect using SisoDb
}

which gives us a model of:

public class Customer
{
    public Guid Id { get; set; }
    public string CustomerNo { get; set; }
    public string Firstname { get; set; }
    public string Lastname { get; set; }
    public Address ShippingAddress { get; set; }
    public Address BillingAddress { get; set; }
}

public class Address
{
    public string Street { get; set; }
    public string Zip { get; set; }
    public string City { get; set; }
    public string Country { get; set; }
}

Note! There are not interfaces, base classes or any junk. We will however need to add one member to the aggregate root (the class being used when storing structures) Customer and that is a property containing the Id: public [int|Guid] Id { get; set; }. You can select between int or Guid, SisoDb will use int as indicator for identities and Guid as indicator for, well Guid’s. SisoDb will take care of the assignment of them.

Pause – lets get some insight to SisoDb and its building blocks

Before continuing and doing what the TODO says, lets learn a bit about the building blocks of SisoDb. There’s a Database and something called a Unit of work (which is transactional) and then there’s…. nothing more! Really, it’s that simple. No mappings, interfaces or base classes. Just you and your Plain Old Clr Objects (POCOs).

The terminology “Structure” is kind of synonym with “Document” which is one popular kind of NoSql storage entity used e.g in MongoDb. You can look at it as a object graph with x number of levels and members on each level. SisoDb will serialize this graph and store it as Json as well as flatten the hierarchy and extract all values of public property that has getters and are simple types (int, strings, decimals, datetimes etc.) and store them in a index table used for querying.

TODO: Connect using SisoDb

Sorry for the details. There is much more info at: http://www.sisodb.com/docs.

The next steps are easy: connect to a database and let SisoDb generate it.

[Test]
public void RegisterNewCustomer()
{
    ....
    ....
    var cnInfo = new SisoConnectionInfo(
        @"sisodb:provider=Sql2008||plain:Data source=.;
        Initial catalog=SisoDbDemo;Integrated security=SSPI;");
    var db = new SisoDatabase(cnInfo);
    db.EnsureNewDatabase(); //Note! This is a test hence it's ok that the database is recreated.

    //TODO: Insert the customer
}

The database is designed for being long lived and is something you would store in your IoC-container. It caches the structure schemes etc. and keeps track of if it has generated tables etc.

TODO: Insert the customer

What we have todo is: Get an unit of work and insert the item and commit the unit of work so that the changes made in the transaction is committed.

[Test]
public void RegisterNewCustomer()
{
    ....
    ....
    Customer refetched = nulll;
    using(var uow = db.CreateUnitOfWork())
    {
        uow.Insert(customer);
        uow.Commit();

        refetched = uow.Query<Customer>(
            c => c.CustomerNo == "Super100").SingleOrDefault();
    }
}
Assert.IsNotNull(refetched);

That’s it for a getting started post. I will be covering a lot more in a near future.

//Daniel

2 thoughts on “SisoDb – Getting started

  1. HI Daniel

    I’ve updated sisodb to v0.7.1 from version 0.6, but getting an error SisoDatabase namespace not found

    • Hi,

      Sorry. I haven’t had the time to update the documentation. Getting right at it now. The SisoDatabase class has been removed since it proxied all calls and I have instead made a factory for creating your database.

      var cnInfo = new SisoConnectionInfo(@"sisodb:provider=Sql2008||plain:Data source=.;Initial catalog=SisoDbLab;Integrated security=SSPI;")
      var db = new SisoDbFactory().CreateDatabase(cnInfo);

      //Daniel

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