/// <summary> /// Executes the scalar function returning the value of a specified type. /// </summary> /// <typeparam name="T">The type of a value to return.</typeparam> /// <param name="client">A client assembly.</param> /// <param name="arguments">Are the arguments to pass.</param> protected T GoFunc <T>(System.Reflection.Assembly client, params ParameterArgument[] arguments) { return(PublicInvoker.Call <T>(() => { var root = Mapper.GetRoot(); DbMapping.CreateParams(root, this); var parameters = String.Join(",", root.AllParams.Select(p => p.Name).ToArray()); // build string sql = Text.GenerateSql(100) .NewLine(Text.Select).S() .Append(Map.Name.Sql) .EncloseLeft() .Append(parameters) .EncloseRight() .Append(Text._As_) .Append(Text.LeftSquareBracket) .Append(Text.SingleColumnName) .Append(Text.RightSquareBracket) .Terminate() .ToString(); Mapper.SetSql(sql); var cpass = new PassChainer(Mapper, arguments); var connectable = Reader.GetConnectable(client, cpass); return Reader.LoadTable <Row <T> >(connectable, null, true).ToValue <T>(); })); }
internal void BuildProc(ParameterArgument[] arguments) { Arguments = arguments; var root = Mapper.GetRoot(); DbMapping.CreateParams(root, this); string parameters = null; if (arguments != null && arguments.Length > 0) { var i = 0; parameters = String.Join(",", root.AllParams .Select(p => { var s = p.Name; if (arguments[i] == null) { arguments[i] = Designer.Null; } if (arguments[i].IsArgumentOutput) { s = String.Format("{0} {1}", s, Text.Output); } ++i; return(s); } )); } string sql = Text.GenerateSql(100) .NewLine(Text.Exec).S() .Append(Text.Reserved.ReturnValueOuterParam).Append(Text._Equal_) .Append(Map.Name.Sql).S() .Append(parameters).Terminate() .NewLine(Text.Set).S() // SET @_ri = @_ro; .Append(Text.Reserved.ReturnValueInnerParam) .Append(Text._Equal_) .Append(Text.Reserved.ReturnValueOuterParam) .Terminate() .ToString(); Mapper.SetSql(sql); }