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

Commit 0e5c42b

Browse files
committed
Change FindColumnIndex to use NamingStrategy when finding columns
1 parent b9dc50b commit 0e5c42b

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/ServiceStack.OrmLite/OrmLiteUtils.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,22 +394,28 @@ public static Tuple<FieldDefinition, int, IOrmLiteConverter>[] GetIndexFieldsCac
394394
private const int NotFound = -1;
395395
internal static int FindColumnIndex(IOrmLiteDialectProvider dialectProvider, FieldDefinition fieldDef, Dictionary<string, int> dbFieldMap)
396396
{
397-
var index = NotFound;
398-
if (!dbFieldMap.TryGetValue(fieldDef.FieldName, out index))
399-
{
400-
index = TryGuessColumnIndex(fieldDef.FieldName, dbFieldMap);
401-
}
397+
int index;
398+
var fieldName = dialectProvider.NamingStrategy.GetColumnName(fieldDef.FieldName);
399+
if (dbFieldMap.TryGetValue(fieldName, out index))
400+
return index;
401+
402+
index = TryGuessColumnIndex(fieldName, dbFieldMap);
403+
if (index != NotFound)
404+
return index;
402405

403406
// Try fallback to original field name when overriden by alias
404-
if (index == NotFound && fieldDef.Alias != null && !OrmLiteConfig.DisableColumnGuessFallback)
407+
if (fieldDef.Alias != null && !OrmLiteConfig.DisableColumnGuessFallback)
405408
{
406-
if (!dbFieldMap.TryGetValue(fieldDef.Name, out index))
407-
{
408-
index = TryGuessColumnIndex(fieldDef.Name, dbFieldMap);
409-
}
409+
var alias = dialectProvider.NamingStrategy.GetColumnName(fieldDef.Name);
410+
if (dbFieldMap.TryGetValue(alias, out index))
411+
return index;
412+
413+
index = TryGuessColumnIndex(alias, dbFieldMap);
414+
if (index != NotFound)
415+
return index;
410416
}
411417

412-
return index;
418+
return NotFound;
413419
}
414420

415421
private static readonly Regex AllowedPropertyCharsRegex = new Regex(@"[^0-9a-zA-Z_]",

tests/ServiceStack.OrmLite.Tests/Expression/ComplexJoinTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,6 @@ public void ComplexJoin_with_SqlExpression()
248248
Assert.That(fooBarBaz.BazId, Is.EqualTo(_baz2Id));
249249
fooBarBaz = results.First(x => x.FooBarBazId == _fooBarBaz2Id);
250250
Assert.That(fooBarBaz.BazId, Is.EqualTo(_baz1Id));
251-
fooBarBaz = results.First(x => x.FooBarBazId == _fooBarBaz2Id);
252-
Assert.That(fooBarBaz.BazId, Is.EqualTo(_baz1Id));
253251
}
254252
}
255253

0 commit comments

Comments
 (0)