|
|
@@ -138,7 +138,41 @@ namespace Business.Core.MongoDBHelper
|
|
|
/// <returns></returns>
|
|
|
public Task DeleteManyByCondition(Expression<Func<T, bool>> filter)
|
|
|
{
|
|
|
- return mongoCollection.DeleteManyAsync<T>(filter);
|
|
|
+ return mongoCollection.DeleteManyAsync(filter);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 根据id删除对象
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ public Task DeleteById(long id)
|
|
|
+ {
|
|
|
+ return mongoCollection.DeleteManyAsync(s => id==s.Id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 根据id列表批量删除 对象
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="ids">id列表</param>
|
|
|
+ public Task DeleteByIds(IEnumerable<long> ids)
|
|
|
+ {
|
|
|
+ return mongoCollection.DeleteManyAsync(s => ids.Contains(s.Id));
|
|
|
+ }
|
|
|
+
|
|
|
+ public Task<DeleteResult> Delete(Expression<Func<T, bool>> expression, bool isOne = false)
|
|
|
+ {
|
|
|
+ if (isOne)
|
|
|
+ return mongoCollection.DeleteOneAsync(expression);
|
|
|
+ else
|
|
|
+ return mongoCollection.DeleteManyAsync(expression);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Task<DeleteResult> Delete(FilterDefinition<T> filter, bool isOne = false)
|
|
|
+ {
|
|
|
+ if (isOne)
|
|
|
+ return mongoCollection.DeleteOneAsync(filter);
|
|
|
+ else
|
|
|
+ return mongoCollection.DeleteManyAsync(filter);
|
|
|
}
|
|
|
}
|
|
|
}
|