|
|
@@ -4,6 +4,10 @@ using System.Linq.Expressions;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using ETModel;
|
|
|
+using MongoDB.Bson;
|
|
|
+using MongoDB.Bson.Serialization;
|
|
|
+using MongoDB.Bson.Serialization.Serializers;
|
|
|
+using MongoDB.Driver;
|
|
|
|
|
|
namespace ETHotfix
|
|
|
{
|
|
|
@@ -57,6 +61,22 @@ namespace ETHotfix
|
|
|
DBQueryResponse dbQueryResponse = (DBQueryResponse)await session.Call(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id, NeedCache = needCache });
|
|
|
return (T)dbQueryResponse.Component;
|
|
|
}
|
|
|
+
|
|
|
+ public static async Task<List<T>> Query<T>(this DBProxyComponent self, Expression<Func<T ,bool>> exp, bool needCache = true) where T: ComponentWithId
|
|
|
+ {
|
|
|
+ List<T> list = new List<T>();
|
|
|
+ Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
|
|
|
+ ExpressionFilterDefinition<T> filter = new ExpressionFilterDefinition<T>(exp);
|
|
|
+ IBsonSerializerRegistry serializerRegistry = BsonSerializer.SerializerRegistry;
|
|
|
+ IBsonSerializer<T> documentSerializer = serializerRegistry.GetSerializer<T>();
|
|
|
+ string json = filter.Render(documentSerializer, serializerRegistry).ToJson();
|
|
|
+ DBQueryJsonResponse dbQueryResponse = (DBQueryJsonResponse)await session.Call(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json });
|
|
|
+ foreach (ComponentWithId component in dbQueryResponse.Components)
|
|
|
+ {
|
|
|
+ list.Add((T)component);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
|
|
|
public static async Task<List<T>> QueryBatch<T>(this DBProxyComponent self, List<long> ids, bool needCache = true) where T : ComponentWithId
|
|
|
{
|
|
|
@@ -69,12 +89,6 @@ namespace ETHotfix
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
-
|
|
|
- public static async Task<List<T>> Query<T>(this DBProxyComponent self, Expression<Func<T, bool>> func) where T : ComponentWithId
|
|
|
- {
|
|
|
- ExpressionVistor vistor = new ExpressionVistor(func);
|
|
|
- return await self.QueryJson<T>(vistor.Output);
|
|
|
- }
|
|
|
|
|
|
public static async Task<List<T>> QueryJson<T>(this DBProxyComponent self, string json) where T : ComponentWithId
|
|
|
{
|