public override int Update <TModel>(LambdaQuery.LambdaQuery <TModel> query1, ParameCollection setValue) { if (query1.__GroupFields.Count > 0) { throw new CRLException("update不支持group查询"); } if (query1.__Relations.Count > 1) { throw new CRLException("update关联不支持多次"); } if (setValue.Count == 0) { throw new ArgumentNullException("更新时发生错误,参数值为空 ParameCollection setValue"); } var query = query1 as LambdaQuery.MongoDBLambdaQuery <TModel>; var collection = _MongoDB.GetCollection <TModel>(query.QueryTableName); var update = Builders <TModel> .Update; var first = setValue.First(); var updateSet = update.Set(first.Key, first.Value); setValue.Remove(first.Key); foreach (var item in setValue) { if (item.Key.StartsWith("$")) { throw new CRLException("MongoDB不支持累加" + item.Key); } update.Set(item.Key, item.Value); } var result = collection.UpdateMany(query.__MongoDBFilter, updateSet); return((int)result.ModifiedCount); }
/// <summary> /// 总是返回简单结果 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parame"></param> /// <param name="count"></param> /// <returns></returns> public List <IProductBase> QuerySimpleListByPage <T>(ParameCollection parame, out int count) where T : IProductBase, new() { parame.Remove("Fields"); parame.SetQueryFields(@"[AddTime] ,[CategoryCode] ,[Id] ,[ProductImage] ,[ProductName] ,[SettlementPrice] ,[SoldPrice] ,[SupplierId],[ProductStatus]"); List <T> list = QueryListByPage <T>(parame, out count); return(ObjectConvert.CloneToSimple <IProductBase, T>(list)); }
//public override int Update<TModel, TJoin>(System.Linq.Expressions.Expression<Func<TModel, TJoin, bool>> expression, ParameCollection updateValue) //{ // throw new NotSupportedException(); //} int Update <TModel>(FilterDefinition <TModel> filter, ParameCollection setValue) { var collection = GetCollection <TModel>(); var update = Builders <TModel> .Update; var first = setValue.First(); var updateSet = update.Set(first.Key, first.Value); setValue.Remove(first.Key); foreach (var item in setValue) { if (item.Key.StartsWith("$")) { throw new CRLException("MongoDB不支持累加" + item.Key); } updateSet = updateSet.Set(item.Key, item.Value); } var result = collection.UpdateMany(filter, updateSet); return((int)result.ModifiedCount); }