private SerializableQuery ConvertToSerializableQuery(Select sourceQuery)
        {
            var targetQuery = new SerializableQuery();

            ApplySelectCondition(targetQuery, sourceQuery.Condition);
            ApplySourceExpressions(targetQuery, sourceQuery.SourceExpression);
            ApplyJoins(targetQuery, sourceQuery.Joins);
            return(targetQuery);
        }
        /// <summary>
        /// Serialize Select to JSON.
        /// </summary>
        /// <param name="sourceQuery">Instance of <see cref="Select"/>.</param>
        /// <returns>Serialized Select JSON data.</returns>
        public string SerializeSelectQuery(Select sourceQuery)
        {
            string            resultJSON = string.Empty;
            SerializableQuery query      = ConvertToSerializableQuery(sourceQuery);

            resultJSON = JsonConvert.SerializeObject(query, Newtonsoft.Json.Formatting.None,
                                                     new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            return(resultJSON);
        }
 private void ApplyJoins(SerializableQuery sourceQuery, IEnumerable <Join> joins)
 {
     sourceQuery.Joins = new List <SerializableJoin>();
     foreach (var joinItem in joins)
     {
         var serializedJoin = new SerializableJoin();
         ApplyJoinCondition(serializedJoin, joinItem.Condition);
         ApplySourceExpressions(serializedJoin, joinItem.SourceExpression);
         sourceQuery.Joins.Add(serializedJoin);
     }
 }
 private void ApplySourceExpressions(SerializableQuery sourceQuery, QuerySourceExpression sourceExpression)
 {
     if (sourceExpression != null)
     {
         sourceQuery.SourceExpression = new SerializableExpression()
         {
             Alias                = sourceExpression.Alias,
             SchemaName           = sourceExpression.SchemaName,
             SourceExpressionType = sourceExpression.ExpressionType
         };
     }
 }
 private void ApplySelectCondition(SerializableQuery query, QueryCondition sourceCondition)
 {
     query.Conditions = ConvertToSerializableCondition(sourceCondition);
 }