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

Commit b916030

Browse files
committed
Fixed construction of "value IN array" SqlExpression when the array is constructed inside the lambda body
1 parent 2d95fd7 commit b916030

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ protected virtual object VisitStaticArrayMethodCall(MethodCallExpression m)
16861686
{
16871687
case "Contains":
16881688
List<Object> args = this.VisitExpressionList(m.Arguments);
1689-
object quotedColName = args[1];
1689+
object quotedColName = args.Last();
16901690

16911691
Expression memberExpr = m.Arguments[0];
16921692
if (memberExpr.NodeType == ExpressionType.MemberAccess)

tests/ServiceStack.OrmLite.Tests/ExpressionVisitorTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ public void Can_Select_using_constant_Yoda_condition()
193193
CollectionAssert.AreEquivalent(new[] { 1, 3, 4 }, target.Select(t => t.Id).ToArray());
194194
}
195195

196+
[Test]
197+
public void Can_Select_using_int_array_constructed_inside_Contains()
198+
{
199+
var q = Db.From<TestType>().Where(x => new int?[] { 10, 30 }.Contains(x.NullableIntCol));
200+
var target = Db.Select(q);
201+
CollectionAssert.AreEquivalent(new[] { 1, 3 }, target.Select(t => t.Id).ToArray());
202+
}
203+
204+
[Test]
205+
public void Can_Select_using_int_list_constructed_inside_Contains()
206+
{
207+
var q = Db.From<TestType>().Where(x => new List<int?> { 10, 30 }.Contains(x.NullableIntCol));
208+
var target = Db.Select(q);
209+
CollectionAssert.AreEquivalent(new[] { 1, 3 }, target.Select(t => t.Id).ToArray());
210+
}
211+
196212
[Test]
197213
public void Can_Select_using_Startswith()
198214
{

0 commit comments

Comments
 (0)