I'm trying to write the following code using 10gen C# drivers for Mongo Db. What I'm trying to achieve here is that write a simple adapter so as to seamlessly cache C# objects.
The RegisterClassMap() is not able to recognize CacheId field from the class contract. I couldn't find enough documentation on MapIdField api.
Can somebody please help ? Thanks in advance !!
public interface ICacheable
{
byte[] CacheId { get; }
}
public class Contract : ICacheable
{
public byte[] CacheId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
public class MongoCacheStore
{
private void RegisterClass<T>() where T : class, ICacheable
{
if (!BsonClassMap.IsClassMapRegistered(typeof(T)))
{
BsonClassMap.RegisterClassMap<T>();
BsonClassMap.RegisterClassMap<T>(cm =>
{
cm.AutoMap();
**cm.MapIdField("CacheId");**
});
}
}
}