Skip to content

Commit 268c8f3

Browse files
committed
CSHARP-1487: fixed issue with the type is operator used on the variable in an Any method.
1 parent 98a1824 commit 268c8f3

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/MongoDB.Driver.Tests/Linq/IntegrationTestBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ private void InsertFirst()
5555
H = 22,
5656
I = new[] { "it", "icky" },
5757
W = 1111
58-
}
58+
},
59+
X = new List<E> { new E { F = 10 }, new V { W = 12 } }
5960
},
6061
G = new[] {
6162
new C
@@ -224,6 +225,8 @@ public class C
224225
public E E { get; set; }
225226

226227
public IEnumerable<C> S { get; set; }
228+
229+
public IEnumerable<E> X { get; set; }
227230
}
228231

229232
public class E

src/MongoDB.Driver.Tests/Linq/Translators/PredicateTranslatorTests.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ public void Any_with_a_predicate_on_scalars()
143143
// })));
144144
}
145145

146+
[Test]
147+
public void Any_with_a_type_is()
148+
{
149+
Assert(
150+
x => x.C.X.Any(y => y is V),
151+
1,
152+
"{\"C.X\": {\"$elemMatch\": {\"_t\": \"V\" } } }");
153+
}
154+
146155
[Test]
147156
public void Any_with_local_contains_on_an_embedded_document()
148157
{
@@ -394,7 +403,7 @@ public void ClassEquals()
394403
Assert(
395404
x => x.C == new C { D = "Dexter" },
396405
0,
397-
"{C: {D: 'Dexter', E: null, S: null}}");
406+
"{C: {D: 'Dexter', E: null, S: null, X: null}}");
398407
}
399408

400409
[Test]
@@ -403,7 +412,7 @@ public void ClassEqualsMethod()
403412
Assert(
404413
x => x.C.Equals(new C { D = "Dexter" }),
405414
0,
406-
"{C: {D: 'Dexter', E: null, S: null}}");
415+
"{C: {D: 'Dexter', E: null, S: null, X: null}}");
407416
}
408417

409418
[Test]
@@ -412,7 +421,7 @@ public void ClassNotEquals()
412421
Assert(
413422
x => x.C != new C { D = "Dexter" },
414423
2,
415-
"{C: {$ne: {D: 'Dexter', E: null, S: null}}}");
424+
"{C: {$ne: {D: 'Dexter', E: null, S: null, X: null}}}");
416425
}
417426

418427
[Test]

src/MongoDB.Driver/Linq/Translators/PredicateTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ private FilterDefinition<BsonDocument> TranslateTypeIsQuery(TypeBinaryExpression
15171517

15181518
var elementName = discriminatorConvention.ElementName;
15191519
IFieldExpression fieldExpression;
1520-
if (TryGetFieldExpression(typeBinaryExpression.Expression, out fieldExpression))
1520+
if (TryGetFieldExpression(typeBinaryExpression.Expression, out fieldExpression) && !string.IsNullOrEmpty(fieldExpression.FieldName))
15211521
{
15221522
elementName = string.Format("{0}.{1}", fieldExpression.FieldName, elementName);
15231523
}

0 commit comments

Comments
 (0)