protected virtual void WriteProcedureBodyReturnValue(CodeWriter writer, DbLinq.Schema.Dbml.Function procedure, string result, GenerationContext context) { Type returnType = GetProcedureType(procedure); if (returnType != null) { writer.WriteLine(writer.GetReturnStatement(writer.GetCastExpression(writer.GetMemberExpression(result, "ReturnValue"), writer.GetLiteralType(returnType), true))); } }
protected virtual ParameterDefinition[] GetProcedureParameters(DbLinq.Schema.Dbml.Function procedure) { var parameters = new List <ParameterDefinition>(); foreach (var parameter in procedure.Parameters) { parameters.Add(GetProcedureParameter(parameter)); } return(parameters.ToArray()); }
protected virtual void WriteProcedureBodyOutParameters(CodeWriter writer, DbLinq.Schema.Dbml.Function procedure, string result, GenerationContext context) { int parameterIndex = 0; foreach (var parameter in procedure.Parameters) { if (parameter.DirectionOut) { WriteProcedureBodyOutParameter(writer, parameter, result, parameterIndex, context); } parameterIndex++; } }
protected override void LoadStoredProcedures(Database schema, SchemaName schemaName, IDbConnection conn, NameFormat nameFormat) { var procs = ReadProcedures(conn, schemaName.DbName); //4a. determine unknown types Dictionary <long, string> typeOidToName = new Dictionary <long, string>(); foreach (DataStoredProcedure proc in procs) { if (proc.proallargtypes == null && !string.IsNullOrEmpty(proc.proargtypes)) { proc.proallargtypes = "{" + proc.proargtypes.Replace(' ', ',') + "}"; //work around pgsql weirdness? } } foreach (DataStoredProcedure proc in procs) { typeOidToName[proc.prorettype] = proc.formatted_prorettype; if (proc.proallargtypes == null) { continue; //no args, no Oids to resolve, skip } string[] argTypes1 = parseCsvString(proc.proallargtypes); //eg. {23,24,1043} var argTypes2 = from t in argTypes1 select long.Parse(t); foreach (long argType in argTypes2) { if (!typeOidToName.ContainsKey(argType)) { typeOidToName[argType] = null; } } } //4b. get names for unknown types GetTypeNames(conn, schemaName.DbName, typeOidToName); //4c. generate dbml objects foreach (DataStoredProcedure proc in procs) { DbLinq.Schema.Dbml.Function dbml_fct = ParseFunction(proc, typeOidToName, nameFormat); if (!SkipProc(dbml_fct.Name)) { schema.Functions.Add(dbml_fct); } } }
protected virtual Type GetProcedureType(DbLinq.Schema.Dbml.Function procedure) { Type type = null; if (procedure.Return != null) { type = GetType(procedure.Return.Type, false); } bool isDataShapeUnknown = procedure.ElementType == null && procedure.BodyContainsSelectStatement && !procedure.IsComposable; if (isDataShapeUnknown) { //if we don't know the shape of results, and the proc body contains some selects, //we have no choice but to return an untyped DataSet. // //TODO: either parse proc body like microsoft, //or create a little GUI tool which would call the proc with test values, to determine result shape. type = typeof(DataSet); } return(type); }
protected virtual string GetProcedureName(DbLinq.Schema.Dbml.Function procedure) { return(procedure.Method ?? procedure.Name); }
protected abstract string WriteProcedureBodyMethodCall(CodeWriter writer, DbLinq.Schema.Dbml.Function procedure, GenerationContext context);