Example #1
0
 public string Generate(ICriterion criterion)
 {
     if (criterion == null)
     {
         return("(1 = 1)");
     }
     if (criterion is BinaryCriterion binary)
     {
         return(Generate(binary));
     }
     else if (criterion is DirectDatabaseCriterion direct)
     {
         return(Generate(direct));
     }
     else if (criterion.PropertyName.Contains("."))
     {
         return(ToSubQuerySql(criterion));
     }
     else
     {
         return(ToSqlOn(criterion, Query.MapColumn(criterion.PropertyName)));
     }
 }
        DatabaseQuery WhereSubquery(string myField, DatabaseQuery subquery, string targetField, string @operator)
        {
            subquery.AliasPrefix = "Subq" + Guid.NewGuid().ToString().Remove("-").Substring(0, 6);

            var sql = subquery.Provider
                      .GenerateSelectCommand(subquery, subquery.MapColumn(targetField));

            sql = $"{MapColumn(myField)} {@operator} ({sql})";
            Criteria.Add(Criterion.FromSql(sql));

            foreach (var subQueryParam in subquery.Parameters)
            {
                Parameters.Add(subQueryParam.Key, subQueryParam.Value);
            }

            return(this);
        }