Skip to content

Commit 36772cf

Browse files
committed
Check the dialect cast type instead
1 parent 8fb1956 commit 36772cf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/NHibernate/Linq/Visitors/HqlGeneratorExpressionVisitor.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,20 @@ private bool IsCastRequired(IType type, IType toType)
607607
return false; // Casting a multi-column type is not possible
608608
}
609609

610+
if (sqlTypes[0].DbType == toSqlTypes[0].DbType)
611+
{
612+
return false;
613+
}
614+
610615
if (type.ReturnedClass.IsEnum && sqlTypes[0].DbType == DbType.String)
611616
{
612617
return false; // Never cast an enum that is mapped as string, the type will provide a string for the parameter value
613618
}
614619

615-
return sqlTypes[0].DbType != toSqlTypes[0].DbType;
620+
// Some dialects can map several sql types into one, cast only if the dialect types are different
621+
var castTypeName = _parameters.SessionFactory.Dialect.GetCastTypeName(sqlTypes[0]);
622+
var toCastTypeName = _parameters.SessionFactory.Dialect.GetCastTypeName(toSqlTypes[0]);
623+
return castTypeName != toCastTypeName;
616624
}
617625

618626
private bool IsCastRequired(System.Type type, string sqlFunctionName)

0 commit comments

Comments
 (0)