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

Commit c0cfdda

Browse files
committed
Add test for using var in subExpr
1 parent 1945549 commit c0cfdda

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/ServiceStack.OrmLite.Tests/Issues/SqlExpressionSubSqlExpressionIssue.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,48 @@ public void Can_compare_null_constant_in_subquery_nested_in_SqlExpression()
6161
results.PrintDump();
6262
}
6363
}
64+
65+
public class Person2
66+
{
67+
[AutoIncrement]
68+
public int Id { get; set; }
69+
70+
public string Name { get; set; }
71+
}
72+
73+
public class Order2
74+
{
75+
[AutoIncrement]
76+
public int Id { get; set; }
77+
78+
[References(typeof(Person2))]
79+
public int Person2Id { get; set; }
80+
81+
public DateTime OrderDate { get; set; }
82+
83+
public int OrderTypeId { get; set; }
84+
}
85+
86+
[Test]
87+
public void Can_reference_variable_in_sub_expression()
88+
{
89+
int orderTypeId = 2;
90+
91+
using (var db = OpenDbConnection())
92+
{
93+
var subExpr = db.From<Order2>()
94+
.Where(y => y.OrderTypeId == orderTypeId)
95+
.Select(y => y.Person2Id);
96+
97+
subExpr.ToSelectStatement().Print();
98+
Assert.That(subExpr.ToSelectStatement().NormalizeSql(), Is.StringContaining("@0"));
99+
100+
var expr = db.From<Person2>()
101+
.Where(x => Sql.In(x.Id, subExpr));
102+
103+
expr.ToSelectStatement().Print();
104+
Assert.That(expr.ToSelectStatement().NormalizeSql(), Is.StringContaining("@0"));
105+
}
106+
}
64107
}
65108
}

0 commit comments

Comments
 (0)