/// <summary>
 ///  将对象内容作为查询条件来物理删除数据
 /// </summary>
 /// <param name="entity"></param>
 public void RemoveSearch(T entity)
 {
     MongoLog.Logger.Debug($"物理删除数据 ==> 类型:[{typeof(T).FullName}]\r\n数据信息为:[{entity.ToJson()}] ");
     try
     {
         var          query  = MongoSerializer.SerializeQueryModel(entity);
         DeleteResult result = MongoCollection.DeleteManyAsync(query).Result;
         if (result.DeletedCount == 0)
         {
             MongoLog.Logger.Debug($"将对象内容作为查询条件来物理删除数据 ==> 无数据被删除。\r\n 类型:[{typeof(T).FullName}]\r\n查询条件为:[{entity.ToJson()}] ");
             return;
         }
         MongoLog.Logger.Debug($"将对象内容作为查询条件来物理删除数据 ==> 已删除数据:{result.DeletedCount}条\r\n 类型:[{typeof(T).FullName}]\r\n查询条件为:[{entity.ToJson()}] ");
     }
     catch (System.TimeoutException te)
     {
         MongoLog.Logger.Warning(te, "数据库链接超时。链接字符串:" + Provider.Connection.ConnectionString());
         throw;
     }
     catch (Exception ex)
     {
         MongoLog.Logger.Warning(ex, "操作异常终止。");
         throw;
     }
 }
Пример #2
0
 /// <summary>
 /// 根据实体来查询
 /// </summary>
 /// <returns></returns>
 public IEnumerable <T> Search(T entity)
 {
     try
     {
         var query = MongoSerializer.SerializeQueryModel(entity);
         return(MongoCollection.FindAsync(query).Result.ToEnumerable());
     }
     catch (System.TimeoutException te)
     {
         MongoLog.Logger.Warning(te, "数据库链接超时。链接字符串:" + Provider.Connection.ConnectionString());
         throw;
     }
     catch (Exception ex)
     {
         MongoLog.Logger.Warning(ex, "操作异常终止。");
         throw;
     }
 }