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

Commit a19af3c

Browse files
committed
Allow include to be case-insensitive
1 parent 239bb63 commit a19af3c

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/ServiceStack.OrmLite/OrmLiteReadCommandExtensions.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,13 @@ public static void LoadReferences<T>(this IDbCommand dbCmd, T instance, string[]
901901
if (include != null)
902902
{
903903
// Check that any include values aren't reference fields of the specified type
904-
var fields = fieldDefs.Select(q => q.FieldName);
905-
var invalid = include.Except(fields).ToList();
904+
var includeLower = include.Map(x => x.ToLower());
905+
var fieldNames = fieldDefs.ConvertAll(q => q.FieldName.ToLower());
906+
var invalid = includeLower.Except(fieldNames).ToList();
906907
if (invalid.Count > 0)
907908
throw new ArgumentException("Fields '{0}' are not Reference Properties of Type '{1}'".Fmt(invalid.Join("', '"), typeof(T).Name));
908909

909-
fieldDefs = fieldDefs.Where(f => include.Contains(f.FieldName)).ToList();
910+
fieldDefs = fieldDefs.Where(f => includeLower.Contains(f.FieldName.ToLower())).ToList();
910911
}
911912

912913
foreach (var fieldDef in fieldDefs)
@@ -932,12 +933,13 @@ internal static List<Into> LoadListWithReferences<Into, From>(this IDbCommand db
932933
if (include != null)
933934
{
934935
// Check that any include values aren't reference fields of the specified From type
935-
var fields = fieldDefs.Select(q => q.FieldName);
936-
var invalid = include.Except(fields).ToList();
936+
var includeLower = include.Map(x => x.ToLower());
937+
var fieldNames = fieldDefs.ConvertAll(q => q.FieldName.ToLower());
938+
var invalid = includeLower.Except(fieldNames).ToList();
937939
if (invalid.Count > 0)
938-
throw new ArgumentException("Fields '{0}' are not Reference Properties of Type '{1}'".Fmt(invalid.Join("', '"), typeof(From).Name));
940+
throw new ArgumentException("Fields '{0}' are not Reference Properties of Type '{1}'".Fmt(invalid.Join("', '"), typeof(T).Name));
939941

940-
fieldDefs = loadList.FieldDefs.Where(f => include.Contains(f.FieldName)).ToList();
942+
fieldDefs = fieldDefs.Where(f => includeLower.Contains(f.FieldName.ToLower())).ToList();
941943
}
942944

943945
foreach (var fieldDef in fieldDefs)

tests/ServiceStack.OrmLite.Tests/LoadReferencesTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,12 @@ public void Can_load_only_included_references()
652652
var dbCustomers = db.LoadSelect<Customer>(q => q.Id == customer.Id, include: new[] { "PrimaryAddress" });
653653
Assert.That(dbCustomers.Count, Is.EqualTo(1));
654654
Assert.That(dbCustomers[0].Name, Is.EqualTo("Customer 1"));
655+
Assert.That(dbCustomers[0].Orders, Is.Null);
656+
Assert.That(dbCustomers[0].PrimaryAddress, Is.Not.Null);
655657

658+
dbCustomers = db.LoadSelect<Customer>(q => q.Id == customer.Id, include: new[] { "primaryaddress" });
659+
Assert.That(dbCustomers.Count, Is.EqualTo(1));
660+
Assert.That(dbCustomers[0].Name, Is.EqualTo("Customer 1"));
656661
Assert.That(dbCustomers[0].Orders, Is.Null);
657662
Assert.That(dbCustomers[0].PrimaryAddress, Is.Not.Null);
658663

@@ -662,6 +667,11 @@ public void Can_load_only_included_references()
662667
Assert.That(dbCustomer.Orders, Is.Null);
663668
Assert.That(dbCustomer.PrimaryAddress, Is.Not.Null);
664669

670+
dbCustomer = db.LoadSingleById<Customer>(customer.Id, include: new[] { "primaryaddress" });
671+
Assert.That(dbCustomer.Name, Is.EqualTo("Customer 1"));
672+
Assert.That(dbCustomer.Orders, Is.Null);
673+
Assert.That(dbCustomer.PrimaryAddress, Is.Not.Null);
674+
665675
dbCustomer = db.LoadSingleById<Customer>(customer.Id, include: x => new { x.PrimaryAddress });
666676
Assert.That(dbCustomer.Name, Is.EqualTo("Customer 1"));
667677
Assert.That(dbCustomer.Orders, Is.Null);

0 commit comments

Comments
 (0)