internal virtual SqlExpression VisitUserRow(SqlUserRow row) { return row; }
private IObjectReaderFactory GetDefaultFactory(MetaType rowType) { if(rowType == null) { throw Error.ArgumentNull("rowType"); } SqlNodeAnnotations annotations = new SqlNodeAnnotations(); Expression tmp = Expression.Constant(null); SqlUserQuery suq = new SqlUserQuery(string.Empty, null, null, tmp); if(TypeSystem.IsSimpleType(rowType.Type)) { // if the element type is a simple type (int, bool, etc.) we create // a single column binding SqlUserColumn col = new SqlUserColumn(rowType.Type, _typeProvider.From(rowType.Type), suq, "", false, suq.SourceExpression); suq.Columns.Add(col); suq.Projection = col; } else { // ... otherwise we generate a default projection SqlUserRow rowExp = new SqlUserRow(rowType.InheritanceRoot, _typeProvider.GetApplicationType((int)ConverterSpecialTypes.Row), suq, tmp); suq.Projection = _translator.BuildProjection(rowExp, rowType, true, null, tmp); } Type resultType = TypeSystem.GetSequenceType(rowType.Type); QueryInfo[] qis = this.BuildQuery(ResultShape.Sequence, resultType, suq, null, annotations); return this.GetReaderFactory(qis[qis.Length - 1].Query, rowType.Type); }
private SqlUserQuery VisitUserQuery(string query, Expression[] arguments, Type resultType) { SqlExpression[] args = new SqlExpression[arguments.Length]; for(int i = 0, n = args.Length; i < n; i++) { args[i] = this.VisitExpression(arguments[i]); } SqlUserQuery suq = new SqlUserQuery(query, null, args, _dominatingExpression); if(resultType != typeof(void)) { Type elementType = TypeSystem.GetElementType(resultType); MetaType mType = _services.Model.GetMetaType(elementType); // if the element type is a simple type (int, bool, etc.) we create // a single column binding if(TypeSystem.IsSimpleType(elementType)) { SqlUserColumn col = new SqlUserColumn(elementType, _typeProvider.From(elementType), suq, "", false, _dominatingExpression); suq.Columns.Add(col); suq.Projection = col; } else { // ... otherwise we generate a default projection SqlUserRow rowExp = new SqlUserRow(mType.InheritanceRoot, _typeProvider.GetApplicationType((int)ConverterSpecialTypes.Row), suq, _dominatingExpression); suq.Projection = _translator.BuildProjection(rowExp, mType, _allowDeferred, null, _dominatingExpression); } } return suq; }
/// <summary> /// Translate a call to a stored procedure /// </summary> private SqlNode TranslateStoredProcedureCall(MethodCallExpression mce, MetaFunction function) { if(!_outerNode) { throw Error.SprocsCannotBeComposed(); } // translate method call into sql function call List<SqlExpression> sqlParams = GetFunctionParameters(mce, function); SqlStoredProcedureCall spc = new SqlStoredProcedureCall(function, null, sqlParams, mce); Type returnType = mce.Method.ReturnType; if(returnType.IsGenericType && (returnType.GetGenericTypeDefinition() == typeof(IEnumerable<>) || returnType.GetGenericTypeDefinition() == typeof(ISingleResult<>))) { // Since this is a single rowset returning sproc, we use the one // and only root metatype. MetaType rowType = function.ResultRowTypes[0].InheritanceRoot; SqlUserRow rowExp = new SqlUserRow(rowType, _typeProvider.GetApplicationType((int)ConverterSpecialTypes.Row), spc, mce); spc.Projection = _translator.BuildProjection(rowExp, rowType, _allowDeferred, null, mce); } else if(!( typeof(IMultipleResults).IsAssignableFrom(returnType) || returnType == typeof(int) || returnType == typeof(int?) )) { throw Error.InvalidReturnFromSproc(returnType); } return spc; }
internal override SqlExpression VisitUserRow(SqlUserRow row) { if(!_isDebugMode) { throw Error.InvalidFormatNode("UserRow"); } return row; }
internal override SqlExpression VisitUserRow(SqlUserRow row) { return new SqlUserRow(row.RowType, row.SqlType, (SqlUserQuery)this.Visit(row.Query), row.SourceExpression); }