Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 276d93f

Browse files
committed
Handle EnumMember's in EnumConverter.ToQuotedString() as well
1 parent acb596c commit 276d93f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/ServiceStack.OrmLite/Converters/SpecialConverters.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public override string ToQuotedString(Type fieldType, object value)
7878
if (!isEnumFlags && long.TryParse(value.ToString(), out var enumValue))
7979
value = Enum.ToObject(fieldType, enumValue);
8080

81-
var enumString = DialectProvider.StringSerializer.SerializeToString(value);
81+
var enumString = enumKind == EnumKind.EnumMember
82+
? value.ToString()
83+
: DialectProvider.StringSerializer.SerializeToString(value);
8284
if (enumString == null || enumString == "null")
8385
enumString = value.ToString();
8486

@@ -136,7 +138,7 @@ public static char ToCharValue(object value)
136138
}
137139

138140
//cache expensive to calculate operation
139-
static readonly ConcurrentDictionary<Type, bool> intEnums = new ConcurrentDictionary<Type, bool>();
141+
static readonly ConcurrentDictionary<Type, bool> intEnums = new();
140142

141143
public static bool IsIntEnum(Type fieldType)
142144
{

tests/ServiceStack.OrmLite.Tests/EnumTests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ public void Can_select_enum_using_tuple()
458458
[Test]
459459
public void Does_insert_types_with_EnumMembers()
460460
{
461-
OrmLiteUtils.PrintSql();
462461
using var db = OpenDbConnection();
463462
db.DropAndCreateTable<TypeWithEnumMember>();
464463

@@ -469,6 +468,19 @@ public void Does_insert_types_with_EnumMembers()
469468
Assert.That(results[1].WorkflowType, Is.EqualTo(WorkflowType.SalesInvoice));
470469
Assert.That(results[2].WorkflowType, Is.EqualTo(WorkflowType.PurchaseInvoice));
471470
}
471+
472+
[Test]
473+
public void Can_query_EnumMembers_with_SqlFmt()
474+
{
475+
using var db = OpenDbConnection();
476+
db.DropAndCreateTable<TypeWithEnumMember>();
477+
478+
var id = 1;
479+
db.Insert(new TypeWithEnumMember {Id = id, WorkflowType = WorkflowType.PurchaseInvoice});
480+
var result = db.Single<TypeWithEnumMember>(
481+
"select * from TypeWithEnumMember as db where db.Id = {0} and db.WorkflowType = {1}".SqlFmt(id, WorkflowType.PurchaseInvoice));
482+
Assert.That(result.WorkflowType, Is.EqualTo(WorkflowType.PurchaseInvoice));
483+
}
472484
}
473485

474486
[EnumAsChar]

0 commit comments

Comments
 (0)