Skip to content

Commit 20635cf

Browse files
Support DBNull in DynamicCompare (#389)
1 parent ef56309 commit 20635cf

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

net/DevExtreme.AspNet.Data.Tests/DynamicBindingTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,26 @@ public void T714342() {
245245

246246
Assert.False(DynamicBindingHelper.ShouldUseDynamicBinding(data.ElementType));
247247
}
248+
249+
[Fact]
250+
public void DBNull() {
251+
dynamic item1 = new ExpandoObject();
252+
dynamic item2 = new ExpandoObject();
253+
item1.p = 123;
254+
item2.p = System.DBNull.Value;
255+
256+
var source = new[] { item1, item2 };
257+
258+
Assert.Equal(1, DataSourceLoader.Load(source, new SampleLoadOptions {
259+
Filter = new object[] { "p", 123 },
260+
RequireTotalCount = true
261+
}).totalCount);
262+
263+
Assert.Equal(1, DataSourceLoader.Load(source, new SampleLoadOptions {
264+
Filter = new object[] { "p", null },
265+
RequireTotalCount = true
266+
}).totalCount);
267+
}
248268
}
249269

250270
}

net/DevExtreme.AspNet.Data/Utils.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public static string[] GetPrimaryKey(Type type) {
9191
}
9292

9393
public static int DynamicCompare(object selectorResult, object clientValue) {
94+
if(selectorResult is DBNull)
95+
selectorResult = null;
96+
9497
if(selectorResult != null)
9598
clientValue = ConvertClientValue(clientValue, selectorResult.GetType());
9699
else

0 commit comments

Comments
 (0)