Skip to content

Commit bb847e1

Browse files
committed
修复query数据bug
1 parent 63d7434 commit bb847e1

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

FirServer/FirServer/Manager/DataManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public T GetDoc<T>(string tabName, Expression<Func<T, bool>> filter)
7373
/// <summary>
7474
/// 组合查询
7575
/// </summary>
76-
public List<T> Query<T>(string tabName, Expression<Func<T, bool>> filter)
76+
public List<T> Query<T>(string tabName, Expression<Func<T, bool>> filter = null)
7777
{
7878
return mongoHelper.Select<T>(tabName, filter);
7979
}

FirServer/FirServer/Model/BaseModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public T GetDoc<T>(Expression<Func<T, bool>> filter)
6666
/// <summary>
6767
/// 查询结果集
6868
/// </summary>
69-
public List<T> Query<T>(Expression<Func<T, bool>> filter)
69+
public List<T> Query<T>(Expression<Func<T, bool>> filter = null)
7070
{
7171
if (string.IsNullOrEmpty(tableName) || dataMgr == null)
7272
{

FirServer/FirServer/Utility/MongoHelper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,17 @@ public async Task<long> CountAsync<T>(string collectionName, Expression<Func<T,
100100

101101

102102
#region Select Function
103-
public List<T> Select<T>(string collectionName, Expression<Func<T, bool>> filter)
103+
public List<T> Select<T>(string collectionName, Expression<Func<T, bool>> filter = null)
104104
{
105105
if (mDatabase == null)
106106
{
107107
throw new Exception("MongoDB database was null!!!");
108108
}
109109
var collection = mDatabase.GetCollection<T>(collectionName);
110-
var result = collection.Find(filter).ToList<T>();
110+
if (filter == null)
111+
{
112+
return collection.Find(new BsonDocument()).ToList<T>();
113+
}
111114
return collection.Find(filter).ToList<T>();
112115
}
113116

0 commit comments

Comments
 (0)