/// <summary> /// Execute an actual query specified in the target language using the sADO connection /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="paramValues"></param> /// <returns></returns> public virtual IEnumerable <T> Execute <T>(QueryCommand <T> query, object[] paramValues) { return(_provider.ToEnumerable <T>(query, paramValues)); }
/// <summary> /// Execute an actual query specified in the target language using the sADO connection /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="paramValues"></param> /// <returns></returns> public virtual IEnumerable <T> Execute <T>(QueryCommand <T> query, object[] paramValues) { //DbCommand cmd = this.GetCommand(query.CommandText, query.ParameterNames, paramValues); //this.LogCommand(cmd); //DbDataReader reader = cmd.ExecuteReader(); //return Project(reader, query.Projector); QueryCommand cmd = new QueryCommand(query.CommandText, _provider); for (int i = 0; i < paramValues.Length; i++) { //need to assign a DbType var valueType = paramValues[i].GetType(); var dbType = Database.GetDbType(valueType); cmd.AddParameter(query.ParameterNames[i], paramValues[i], dbType); } /* * var reader = _provider.ExecuteReader(cmd); * var result = Project(reader, query.Projector); * return result; */ IEnumerable <T> result; Type type = typeof(T); //this is so hacky - the issue is that the Projector below uses Expression.Convert, which is a bottleneck //it's about 10x slower than our ToEnumerable. Our ToEnumerable, however, stumbles on Anon types and groupings //since it doesn't know how to instantiate them (I tried - not smart enough). So we do some trickery here. if (type.Name.Contains("AnonymousType") || type.Name.StartsWith("Grouping`") || type.FullName.StartsWith("System.")) { var reader = _provider.ExecuteReader(cmd); result = Project(reader, query.Projector); } else { using (var reader = _provider.ExecuteReader(cmd)) { //use our reader stuff //thanks to Pascal LaCroix for the help here... var resultType = typeof(T); if (resultType.IsValueType) { result = reader.ToEnumerableValueType <T>(); } else { if (query.ColumnNames.Count != 0) //mike check to see if we have ColumnNames { result = reader.ToEnumerable <T>(query.ColumnNames); } else { result = reader.ToEnumerable <T>(null); } } } } return(result); }