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

Commit a44a1d2

Browse files
committed
Added tests for LoadSingleById
1 parent 9817cf8 commit a44a1d2

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/ServiceStack.OrmLite/OrmLiteReadCommandExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ internal static T LoadSingleById<T>(this IDbCommand dbCmd, object value, string[
884884
if (row == null)
885885
return default(T);
886886

887-
dbCmd.LoadReferences(row);
887+
dbCmd.LoadReferences(row, include);
888888

889889
return row;
890890
}
@@ -905,7 +905,7 @@ public static void LoadReferences<T>(this IDbCommand dbCmd, T instance, string[]
905905
fieldDefs = fieldDefs.Where(fd => include.Contains(fd.FieldName)).ToList();
906906
}
907907

908-
foreach (var fieldDef in loadRef.FieldDefs)
908+
foreach (var fieldDef in fieldDefs)
909909
{
910910
dbCmd.Parameters.Clear();
911911
var listInterface = fieldDef.FieldType.GetTypeWithGenericInterfaceOf(typeof(IList<>));

tests/ServiceStack.OrmLite.Tests/LoadReferencesTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,13 @@ public void Can_load_only_included_references()
656656
Assert.That(dbCustomers[0].Orders, Is.Null);
657657
Assert.That(dbCustomers[0].PrimaryAddress, Is.Not.Null);
658658

659+
// Test LoadSingleById
660+
var dbCustomer = db.LoadSingleById<Customer>(customer.Id, include: new[] { "PrimaryAddress" });
661+
Assert.That(dbCustomer.Name, Is.EqualTo("Customer 1"));
662+
663+
Assert.That(dbCustomer.Orders, Is.Null);
664+
Assert.That(dbCustomer.PrimaryAddress, Is.Not.Null);
665+
659666

660667
// Invalid field name
661668
try
@@ -670,6 +677,20 @@ public void Can_load_only_included_references()
670677
{
671678
Assert.Fail();
672679
}
680+
681+
682+
try
683+
{
684+
dbCustomer = db.LoadSingleById<Customer>(customer.Id, include: new[] { "InvalidOption1", "InvalidOption2" });
685+
Assert.Fail();
686+
}
687+
catch (System.ArgumentException ex)
688+
{
689+
}
690+
catch (System.Exception ex)
691+
{
692+
Assert.Fail();
693+
}
673694
}
674695

675696
[Test]

0 commit comments

Comments
 (0)