/// <summary> /// /// </summary> /// <param name="entity"></param> public void Insert(object entity) { try { Type type = entity.GetType(); string name = type.Name; MongoCollection <BsonDocument> records = this.Database.GetCollection <BsonDocument>(name); SerializeResult ser = Serialize(entity, true); BsonDocument doc = ser.Document; records.Insert(doc); _cache.Add(GetCacheKey(ser.Id), entity); } catch (MongoConnectionException) { throw new MongoUnavailableException(); } }
/// <summary> /// /// </summary> /// <param name="entity"></param> public void Update(object entity) { try { Type type = entity.GetType(); string name = type.Name; MongoCollection <BsonDocument> records = this.Database.GetCollection <BsonDocument>(name); SerializeResult ser = Serialize(entity, false); records.Update(Query.EQ("_id", ser.Id), new UpdateDocument { { "$set", ser.Document } }); _cache.Add(GetCacheKey(ser.Id), entity); } catch (MongoConnectionException) { throw new MongoUnavailableException(); } }