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

Commit ca7567b

Browse files
committed
Merge branch 'master' of github.com:ServiceStack/ServiceStack.OrmLite
2 parents 9e2948b + 1d798bc commit ca7567b

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,12 @@ protected bool CheckExpressionForTypes(Expression e, ExpressionType[] types)
15251525
{
15261526
for (var i = 0; i < methodCallExpr.Arguments.Count; i++)
15271527
{
1528-
if (CheckExpressionForTypes(methodCallExpr.Arguments[0], types))
1528+
if (CheckExpressionForTypes(methodCallExpr.Arguments[i], types))
15291529
return true;
15301530
}
1531+
1532+
if (CheckExpressionForTypes(methodCallExpr.Object, types))
1533+
return true;
15311534
}
15321535

15331536
var unaryExpr = e as UnaryExpression;
@@ -1811,16 +1814,27 @@ protected virtual object VisitConditional(ConditionalExpression e)
18111814
if ((bool) test)
18121815
{
18131816
var ifTrue = Visit(e.IfTrue);
1817+
if (e.IfTrue.Type == typeof(string) && !(ifTrue is PartialSqlString))
1818+
ifTrue = ConvertToParam(ifTrue);
1819+
18141820
return ifTrue;
18151821
}
18161822

18171823
var ifFalse = Visit(e.IfFalse);
1824+
if (e.IfFalse.Type == typeof(string) && !(ifFalse is PartialSqlString))
1825+
ifFalse = ConvertToParam(ifFalse);
1826+
18181827
return ifFalse;
18191828
}
18201829
else
18211830
{
18221831
var ifTrue = Visit(e.IfTrue);
1832+
if (e.IfTrue.Type == typeof(string) && !(ifTrue is PartialSqlString))
1833+
ifTrue = ConvertToParam(ifTrue);
1834+
18231835
var ifFalse = Visit(e.IfFalse);
1836+
if (e.IfFalse.Type == typeof(string) && !(ifFalse is PartialSqlString))
1837+
ifFalse = ConvertToParam(ifFalse);
18241838

18251839
return new PartialSqlString($"(CASE WHEN {test} THEN {ifTrue} ELSE {ifFalse} END)");
18261840
}

tests/ServiceStack.OrmLite.Tests/ExpressionVisitorTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,28 @@ public void Can_Where_using_SqlIn_filter()
564564
Assert.That(target.Count, Is.EqualTo(1));
565565
}
566566

567+
[Test]
568+
public void Can_Where_using_IfConcat_filter()
569+
{
570+
System.Linq.Expressions.Expression<Func<TestType, bool>> filter = x => (String.Concat("Text: ", x.TextCol) == null ? null : String.Concat("Text: ", x.TextCol)).EndsWith("asdf");
571+
var q = Db.From<TestType>().Where(filter);
572+
Assert.That(q.ToSelectStatement(), Does.Contain("Text"));
573+
574+
var target = Db.Select(q);
575+
Assert.That(target.Count, Is.EqualTo(1));
576+
}
577+
578+
[Test]
579+
public void Can_Where_using_IfWithStringConstant_filter()
580+
{
581+
System.Linq.Expressions.Expression<Func<TestType, bool>> filter = x => (String.Concat("Text: ", x.TextCol) == null ? " " : String.Concat("Text: ", x.TextCol)).EndsWith("asdf");
582+
var q = Db.From<TestType>().Where(filter);
583+
Assert.That(q.ToSelectStatement(), Does.Contain("Text"));
584+
585+
var target = Db.Select(q);
586+
Assert.That(target.Count, Is.EqualTo(1));
587+
}
588+
567589
private int MethodReturningInt(int val)
568590
{
569591
return val;

0 commit comments

Comments
 (0)