public PgSqlCommand GetSqlCommand(TableDefinition tableDefinition) { var command = new PgSqlCommand(); var lsql = new List <string>(); bool not = false; foreach (var xpression in Xpressions) { if (xpression is ExpressionNot) { not = true; continue; } ColumnBuilder column = null; if (xpression.ColumnName != null) { column = tableDefinition.GetColumnBuilderByDbName(xpression.ColumnName); } var comm = xpression.GetSqlCommand(column); if (not) { comm.Command = $"NOT {comm.Command}"; } comm.Parameters.ForEach(p => { if (p.Value.GetType().IsEnum) { p.Value = p.Value.ToString(); } if (command.ParameterIdExists(p.UniqueId)) { var newParam = p.RebuildWithNewId(); comm.Command = comm.Command.Replace($"@{p.UniqueId}", $"@{newParam.UniqueId}"); command.Parameters.Add(newParam); } else { command.Parameters.Add(p); } }); lsql.Add($"({comm.Command})"); not = false; } command.Command = String.Join(" AND ", lsql); return(command); }