Skip to content

Commit f33c42f

Browse files
committed
Check the dialect cast type instead
1 parent 171dd10 commit f33c42f

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
@@ -609,12 +609,20 @@ private bool IsCastRequired(IType type, IType toType)
609609
return false; // Casting a multi-column type is not possible
610610
}
611611

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

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

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

0 commit comments

Comments
 (0)