Skip to content

Commit 5321b74

Browse files
committed
Fix for issue ThatRendle#189
1 parent 6a703b2 commit 5321b74

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Simple.Data.Ado/EagerLoadingEnumerable.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private class WithContainer
107107

108108
public void AddToCollection(IDictionary<string,object> row)
109109
{
110+
if (row.All(kvp => ReferenceEquals(null, kvp.Value))) return;
110111
if (Collection == null) Collection = new HashSet<IDictionary<string, object>>(new DictionaryEqualityComparer());
111112
Collection.Add(row);
112113
}

Simple.Data.SqlTest/QueryTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,17 @@ public void WithClauseShouldCastToStaticTypeWithCollection()
392392
Assert.AreEqual(1, actual.Orders.Single().OrderId);
393393
Assert.AreEqual(new DateTime(2010,10,10), actual.Orders.Single().OrderDate);
394394
}
395+
396+
[Test]
397+
public void WithClauseShouldCastToStaticTypeWithEmptyCollection()
398+
{
399+
var db = DatabaseHelper.Open();
400+
var newCustomer = db.Customers.Insert(Name: "No Orders");
401+
Customer actual = db.Customers.FindAllByCustomerId(newCustomer.CustomerId).WithOrders().FirstOrDefault();
402+
Assert.IsNotNull(actual);
403+
Assert.IsNotNull(actual.Orders);
404+
Assert.AreEqual(0, actual.Orders.Count);
405+
}
395406

396407
[Test]
397408
public void SelfJoinShouldNotThrowException()

0 commit comments

Comments
 (0)