From 6d31b4d0d85e5ccebb8cc648eadc9769641707b4 Mon Sep 17 00:00:00 2001 From: tanghai Date: Fri, 25 May 2018 11:01:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8Bdb=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E5=87=8F=E5=B0=91gc=EF=BC=8C=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E7=BB=93=E6=9E=9C=E8=BF=94=E5=9B=9EList=EF=BC=8C=E8=BF=99=E6=A0=B7=E5=B0=91=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E4=B8=80=E4=B8=AAList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Module/DB/DBProxyComponentSystem.cs | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/Server/Hotfix/Module/DB/DBProxyComponentSystem.cs b/Server/Hotfix/Module/DB/DBProxyComponentSystem.cs index 380d0799..5b1a65cd 100644 --- a/Server/Hotfix/Module/DB/DBProxyComponentSystem.cs +++ b/Server/Hotfix/Module/DB/DBProxyComponentSystem.cs @@ -62,44 +62,41 @@ namespace ETHotfix return (T)dbQueryResponse.Component; } - public static async Task> Query(this DBProxyComponent self, Expression> exp, bool needCache = true) where T: ComponentWithId + /// + /// 根据查询表达式查询 + /// + /// + /// + /// + /// + public static async Task> Query(this DBProxyComponent self, Expression> exp) where T: ComponentWithId { - List list = new List(); - Session session = Game.Scene.GetComponent().Get(self.dbAddress); ExpressionFilterDefinition filter = new ExpressionFilterDefinition(exp); IBsonSerializerRegistry serializerRegistry = BsonSerializer.SerializerRegistry; IBsonSerializer documentSerializer = serializerRegistry.GetSerializer(); 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; + return await self.Query(json); } - public static async Task> QueryBatch(this DBProxyComponent self, List ids, bool needCache = true) where T : ComponentWithId + public static async Task> Query(this DBProxyComponent self, List ids, bool needCache = true) where T : ComponentWithId { - List list = new List(); Session session = Game.Scene.GetComponent().Get(self.dbAddress); DBQueryBatchResponse dbQueryBatchResponse = (DBQueryBatchResponse)await session.Call(new DBQueryBatchRequest { CollectionName = typeof(T).Name, IdList = ids, NeedCache = needCache}); - foreach (ComponentWithId component in dbQueryBatchResponse.Components) - { - list.Add((T)component); - } - return list; + return dbQueryBatchResponse.Components; } - public static async Task> QueryJson(this DBProxyComponent self, string json) where T : ComponentWithId + /// + /// 根据json查询条件查询 + /// + /// + /// + /// + /// + public static async Task> Query(this DBProxyComponent self, string json) where T : ComponentWithId { - List list = new List(); Session session = Game.Scene.GetComponent().Get(self.dbAddress); DBQueryJsonResponse dbQueryJsonResponse = (DBQueryJsonResponse)await session.Call(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json }); - foreach (ComponentWithId component in dbQueryJsonResponse.Components) - { - list.Add((T)component); - } - return list; + return dbQueryJsonResponse.Components; } } } \ No newline at end of file -- GitLab