Example #1
0
        public Task <ReplaceOneResult> UpdateAsync <T>(string Name, Type Type, T Document)
        {
            if (MongoMapperTransaction.InTransaction && !MongoMapperTransaction.Commiting)
            {
                MongoMapperTransaction.AddToQueue(OperationType.Update, Type, Document);
                Task.FromResult(true);
            }

            var mongoMapperVersionable = Document as IMongoMapperVersionable;
            var mongoMapperIdeable     = Document as IMongoMapperIdeable;

            if (mongoMapperVersionable != null)
            {
                mongoMapperVersionable.m_dv++;
            }

            Debug.Assert(mongoMapperIdeable != null, "mongoMapperIdeable != null");

            return(CollectionsManager.GetCollection <T>(Name).ReplaceOneAsync(
                       Builders <T> .Filter.Eq("_id", mongoMapperIdeable.m_id),
                       Document,
                       new UpdateOptions {
                IsUpsert = true
            }
                       ));
        }
Example #2
0
        public Task <DeleteResult> DeleteAsync <T>(string Name, Type Type, T Document)
        {
            if (MongoMapperTransaction.InTransaction && !MongoMapperTransaction.Commiting)
            {
                MongoMapperTransaction.AddToQueue(OperationType.Delete, Type, Document);
                Task.FromResult(true);
            }

            var mongoMapperIdeable = Document as IMongoMapperIdeable;

            Debug.Assert(mongoMapperIdeable != null, "mongoMapperIdeable != null");

            if (mongoMapperIdeable.m_id == default(long))
            {
                mongoMapperIdeable.m_id = Finder.Instance.FindIdByKey <T>(Type,
                                                                          MongoMapperHelper.GetPrimaryKey(Type).
                                                                          ToDictionary(
                                                                              KeyField => KeyField,
                                                                              KeyField =>
                                                                              ReflectionUtility.
                                                                              GetPropertyValue(
                                                                                  this, KeyField)));
            }

            var query = Builders <T> .Filter.Eq("_id", mongoMapperIdeable.m_id);

            return(CollectionsManager.GetCollection <T>(Type.Name).DeleteOneAsync(query));
        }
Example #3
0
        public Task InsertAsync <T>(string Name, Type Type, T Document)
        {
            if (MongoMapperTransaction.InTransaction && !MongoMapperTransaction.Commiting)
            {
                MongoMapperTransaction.AddToQueue(OperationType.Insert, Type, Document);
                Task.FromResult(true);
            }

            var mongoMapperVersionable = Document as IMongoMapperVersionable;

            if (mongoMapperVersionable != null)
            {
                mongoMapperVersionable.m_dv++;
            }

            return(CollectionsManager.GetCollection <T>(Name).InsertOneAsync(Document));
        }