Repository navigation
Cassandra Object Mapper
The Cassandra Object Mapper is a framework that allows easy mapping of CLR objects to and from Cassandra rows/records. Cassandra terminology can take a lot of getting used to, and this article may not always get it right (it’s a wiki – fix it). The general idea is that we’d like to create a plain old .Net class, adorn it with some attributes, and then be able to load and save it from Cassandra, including lazy loading “related” Cassandra objects. Our not-so-hypothetical example will be a simple Customer object. We’ve named the object CCustomer, because we also use a relational store for things which require transactional consistency, and that uses BLToolkit to generate entities from the database, so it gets to keep the “Customer” class name. Sorry Cassandra, maybe someday you can has Customer.
So, our declaration looks like this:
///
/// A customer record from Cassandra
///
[CassandraEntity(typeof(int), CassandraInterface.Keyspace, CassandraInterface.ColumnFamily.Customer)]
public class CCustomer : CassandraEntity
{
///
/// Needs to be here for the serializer
///
public CCustomer() { }
///
/// Construct a record for a given relational customer id
///
///
public CCustomer(int id) : base(id.ToString())
{
}
public int CustomerId { get { return int.Parse(RowKey); } }
[CassandraRow(typeof(CImageContent))]
public CassandraRowReference Photo;
}