/// <summary> /// Insert a generic MongoEntity which is in New state /// </summary> public void GenericInsert(MongoContext ctx, MongoEntity ent) { if (ctx.Debug) { Debug.WriteLine($"Insert ent type={ent.GetType()} id={ent.Id}"); } Collection.InsertOne((T)ent); }
/// <summary> /// enclose the given entity taking a backup /// </summary> public AttachedMongoEntity(MongoEntity entity, Type type = null) { type = type ?? entity.GetType(); NominalType = type; Entity = entity; ResetOrigEntity(); }
/// <summary> /// Remove a generic MongoEntity which is in Deleted state /// </summary> /// <param name="ent"></param> public void GenericDelete(MongoContext ctx, MongoEntity ent) { if (ctx.Debug) { Debug.WriteLine($"Delete ent type={ent.GetType()} id={ent.Id}"); } var filter = Builders <T> .Filter.Eq((x) => x.Id, ent.Id); Collection.DeleteOne(filter); }