Skip to content

Commit d825ec0

Browse files
committed
Check if enum is mapped as any kind of string
1 parent a2a808e commit d825ec0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/NHibernate/Linq/Visitors/HqlGeneratorExpressionVisitor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ private bool IsCastRequired(IType type, IType toType, out bool existType)
634634
return false;
635635
}
636636

637-
if (type.ReturnedClass.IsEnum && sqlTypes[0].DbType == DbType.String)
637+
if (type.ReturnedClass.IsEnum && sqlTypes[0].DbType.IsStringType())
638638
{
639639
existType = false;
640640
return false; // Never cast an enum that is mapped as string, the type will provide a string for the parameter value
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Data;
2+
3+
namespace NHibernate.Util
4+
{
5+
public static class DbTypeExtensions
6+
{
7+
/// <summary>
8+
/// Checks whether the type is a <see cref="DbType.String"/>, <see cref="DbType.AnsiString"/>, <see cref="DbType.StringFixedLength"/> or <see cref="DbType.AnsiStringFixedLength"/>
9+
/// </summary>
10+
/// <param name="dbType"></param>
11+
/// <returns></returns>
12+
public static bool IsStringType(this DbType dbType) => dbType == DbType.String || dbType == DbType.AnsiString || dbType == DbType.StringFixedLength || dbType == DbType.AnsiStringFixedLength;
13+
}
14+
}

0 commit comments

Comments
 (0)