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

Commit 454ef31

Browse files
OlegNadymovmythz
authored andcommitted
Fix for parsing static method inside non-static method. (#616)
* Support for Conditional expression in filter * Fixes for conditional expressions in filter and sorting * Using GetFieldValue in InsertOnly just like in Insert. * Change SqliteBoolConverter DbType to Int32 * Unit test for SqliteBoolConverter, InsertOnly * Fix for parsing static method inside non-static method. * Just formatting * Change access modifier to public for method "IsSqlClass"
1 parent ba74dc6 commit 454ef31

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ private SqlExpression<T> OrderByInternal(Expression keySelector)
794794
return this;
795795
}
796796

797-
private static bool IsSqlClass(object obj)
797+
public static bool IsSqlClass(object obj)
798798
{
799799
return obj != null &&
800800
(obj is PartialSqlString ||
@@ -2104,7 +2104,18 @@ private object GetNotValue(object o)
21042104
protected virtual bool IsColumnAccess(MethodCallExpression m)
21052105
{
21062106
if (m.Object == null)
2107+
{
2108+
foreach (var arg in m.Arguments)
2109+
{
2110+
if (!(arg is LambdaExpression) &&
2111+
IsParameterAccess(arg))
2112+
{
2113+
return true;
2114+
}
2115+
}
2116+
21072117
return false;
2118+
}
21082119

21092120
if (m.Object is MethodCallExpression methCallExp)
21102121
return IsColumnAccess(methCallExp);
@@ -2131,12 +2142,12 @@ protected virtual object VisitMethodCall(MethodCallExpression m)
21312142
if (IsEnumerableMethod(m))
21322143
return VisitEnumerableMethodCall(m);
21332144

2134-
if (IsColumnAccess(m))
2135-
return VisitColumnAccessMethod(m);
2136-
21372145
if (IsStaticStringMethod(m))
21382146
return VisitStaticStringMethodCall(m);
21392147

2148+
if (IsColumnAccess(m))
2149+
return VisitColumnAccessMethod(m);
2150+
21402151
return EvaluateExpression(m);
21412152
}
21422153

tests/ServiceStack.OrmLite.Tests/ExpressionVisitorTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,19 @@ public void Can_Where_using_Constant_in_Conditional_order7()
861861
Assert.AreEqual("asdf", text);
862862
}
863863

864+
[Test]
865+
public void Can_Where_using_StaticInsideNonStaticMethod()
866+
{
867+
System.Linq.Expressions.Expression<Func<TestType, bool>> filter = x => String.Concat(x.TextCol, "test").StartsWith("asdf");
868+
var q = Db.From<TestType>().Where(filter).OrderBy(x => x.Id);
869+
Assert.That(q.ToSelectStatement().ToLower(), Does.Not.Contain(SqlExpression<TestType>.TrueLiteral));
870+
871+
var target = Db.Select(q);
872+
Assert.That(target.Count, Is.EqualTo(2));
873+
var text = target[0].TextCol;
874+
Assert.AreEqual("asdf", text);
875+
}
876+
864877
private int MethodReturningInt(int val)
865878
{
866879
return val;

0 commit comments

Comments
 (0)