Skip to content

Commit 9953a03

Browse files
Saad HESSANEfredericDelaporte
Saad HESSANE
authored andcommitted
Fix Exception Column 'SQL_TYPE_NAME' does not belong to table DataTypes
1 parent 5b56e1b commit 9953a03

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/NHibernate/Dialect/Schema/DB2MetaData.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Data;
44
using System.Data.Common;
5+
using System.Linq;
56

67
namespace NHibernate.Dialect.Schema
78
{
@@ -31,13 +32,20 @@ public override ISet<string> GetReservedWords()
3132
result.Add(row["ReservedWord"].ToString());
3233
}
3334

34-
if (IncludeDataTypesInReservedWords)
35+
if (!IncludeDataTypesInReservedWords)
36+
return result;
37+
38+
var dtTypes = Connection.GetSchema(DbMetaDataCollectionNames.DataTypes);
39+
40+
var typeNameColumn = dtTypes.Columns.Cast<DataColumn>()
41+
.FirstOrDefault(column => column.ColumnName == "SQL_TYPE_NAME");
42+
43+
if (typeNameColumn == null) //todo We can try to fallback to "TypeName" columnName
44+
return result;
45+
46+
foreach (DataRow row in dtTypes.Rows)
3547
{
36-
var dtTypes = Connection.GetSchema(DbMetaDataCollectionNames.DataTypes);
37-
foreach (DataRow row in dtTypes.Rows)
38-
{
39-
result.Add(row["SQL_TYPE_NAME"].ToString());
40-
}
48+
result.Add(row[typeNameColumn].ToString());
4149
}
4250

4351
return result;

0 commit comments

Comments
 (0)