protected IQuery ParseComplexQuery(QueryType type, object query, IEnumerable <object> parms) { IQuery outputQuery = null; // We always want to parse the parameters. But if the thing passed to us as "query" is not a string, then // just assume that all the parms are option type parameters and don't pass a query to ParameterParser string querySource = query is string? (string)query: ""; ParameterParser pp = new ParameterParser(querySource, parms); CopyDbOptions(pp); if (Utils.IsNumericType(query)) { // It's a single numeric value - assume it's a primary key ExpectNoParameters(pp.Parameters); var classInfo = IQ.GetClassInfo <T>(); ISqlQuery queryPK = classInfo.Query(type); queryPK.AddWhereParam(classInfo.PrimaryKey.Name, query); outputQuery = queryPK; } else if (query is string) { bool isMappable = Utils.IsMappableClass <T>(); // First check if its a single named field if (isMappable) { var classInfo = IQ.GetClassInfo <T>(); // Try to create a valid raw query.. if it's not valid, assume it's a where if (pp.QueryType == QueryType.Invalid) { ISqlQuery queryPK = classInfo.Query(type); queryPK.AddWhere(pp.Query); queryPK.AddParameter(pp.Parameters); outputQuery = queryPK; } else { outputQuery = pp.GetIQuery(); } } else { // it's mapped to a primitive type - outputQuery = pp.GetIQuery(); } } if (outputQuery.QueryType != type) { throw new IQException("Wrong type of query passed to method: was " + outputQuery.ToString() + ", expected " + type.ToString()); } return(outputQuery); }