提交 0d9780f4 编写于 作者: pk27602017's avatar pk27602017

修改Lambda表达式的实现

上级 f229469e
......@@ -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
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册