From 9d339a4d3a3c743fa932a2c785a903838eecd013 Mon Sep 17 00:00:00 2001 From: Bourne Shi Date: Thu, 17 Oct 2024 18:27:18 +0800 Subject: [PATCH] feat: optimize property type nullable --- .../Linq/GeneratorExpressionTreeVisitor.cs | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/AElf.EntityMapping.Elasticsearch/Linq/GeneratorExpressionTreeVisitor.cs b/src/AElf.EntityMapping.Elasticsearch/Linq/GeneratorExpressionTreeVisitor.cs index 62e426c..271373d 100644 --- a/src/AElf.EntityMapping.Elasticsearch/Linq/GeneratorExpressionTreeVisitor.cs +++ b/src/AElf.EntityMapping.Elasticsearch/Linq/GeneratorExpressionTreeVisitor.cs @@ -313,31 +313,56 @@ private void HandleNestedContains(SubQueryExpression subQueryExpression, Express private Node GetDifferentTypesTermsQueryNode() { Node query; - if (PropertyType == typeof(Guid) || PropertyType == typeof(Guid?)) + if (PropertyType == typeof(Guid)) { query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); } - else if (PropertyType == typeof(int) || PropertyType == typeof(int?)) + else if (PropertyType == typeof(Guid?)) + { + query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); + } + else if (PropertyType == typeof(int)) { query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); } - else if (PropertyType == typeof(long) || PropertyType == typeof(long?)) + else if (PropertyType == typeof(int?)) + { + query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); + } + else if (PropertyType == typeof(long)) { query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); } - else if (PropertyType == typeof(double) || PropertyType == typeof(double?)) + else if (PropertyType == typeof(long?)) + { + query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); + } + else if (PropertyType == typeof(double)) { query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); } - else if (PropertyType == typeof(DateTime) || PropertyType == typeof(DateTime?)) + else if(PropertyType == typeof(double?)) + { + query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); + } + else if (PropertyType == typeof(DateTime)) { query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); } - else if (PropertyType == typeof(bool) || PropertyType == typeof(bool?)) + else if (PropertyType == typeof(DateTime?)) + { + query = new TermsNode(PropertyName, + ((IEnumerable)Value).Select(x => x.ToString())); + } + else if (PropertyType == typeof(bool)) { query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); } + else if (PropertyType == typeof(bool?)) + { + query = new TermsNode(PropertyName, ((IEnumerable)Value).Select(x => x.ToString())); + } else if (PropertyType == typeof(string)) { query = new TermsNode(PropertyName, (IEnumerable)Value);