We use OracleDataAdaptor.FillSchema so we can work out the datatypes.
This works fine- but for varchar/string types the MaxLength of the datatable column is always -1.
The code generation doesn't know the underlying tables so it can't query All_columns directly. In most cases the stored procedures are simple selects over 1 table or simple joins, returning a one cursor.
Microsoft.Data.OracleClient does the same - it is always MaxLength = -1 -, but ODP (2.112.2.0) gives us the correct length from the underlying table.
All other metadata- datatype, precision, scale, nullability - are fine, but not maxlength. Can the length be made available?
Code: Select all
var resultSet = new DataSet();
using (var con = new OracleConnection(connectionString))
{
con.Open();
using (var command = new OracleCommand(storedProcedure, con))
{
command.CommandType = CommandType.StoredProcedure;
using (var adapter = new OracleDataAdapter(command))
{
adapter.FillSchema(resultSet, SchemaType.Source);
}
}
}
Code: Select all
foreach (DataTable table in resultSet.Tables)
{
foreach (DataColumn column in table.Columns)
{
Console.WriteLine(column.ColumnName + " " + column.DataType.Name + " " + column.MaxLength);
}
}