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

Commit 22770ba

Browse files
OlegNadymovmythz
authored andcommitted
VisitLengthStringProperty fix for CustomSqlExpression (#618)
* 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" * Add support for using the Length property of String * VisitLengthStringProperty fix for CustomSqlExpression
1 parent 383b25d commit 22770ba

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,6 +2471,14 @@ protected virtual object VisitStaticStringMethodCall(MethodCallExpression m)
24712471
private object VisitLengthStringProperty(MemberExpression m)
24722472
{
24732473
var sql = Visit(m.Expression);
2474+
if (!IsSqlClass(sql))
2475+
{
2476+
if (sql == null)
2477+
return 0;
2478+
2479+
sql = ((string) sql).Length;
2480+
return sql;
2481+
}
24742482

24752483
return ToLengthPartialString(sql);
24762484
}

tests/ServiceStack.OrmLite.Tests/CustomSqlExpressionTests.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public override SqlExpression<T> SqlExpression<T>()
9191
}
9292
}
9393

94-
public class CustomSqlExpression<T> : SqlExpression<T>
94+
public class CustomSqlExpression<T> : SqliteExpression<T>
9595
{
9696

9797
public CustomSqlExpression(IOrmLiteDialectProvider dialectProvider) : base(dialectProvider)
@@ -553,5 +553,55 @@ public void Can_Having_using_constant()
553553
var target = Db.Column<string>(q);
554554
Assert.AreEqual(3, target.Count);
555555
}
556+
557+
[Test]
558+
public void Can_Where_using_StringLengthVirtualProperty1()
559+
{
560+
System.Linq.Expressions.Expression<Func<WaybillBase, bool>> filter = x => x.VirtProperty.Length == 0;
561+
562+
var q = Db.From<WaybillBase>().Where(filter);
563+
var target = Db.Select(q);
564+
Assert.AreEqual(0, target.Count);
565+
}
566+
567+
[Test]
568+
public void Can_Where_using_StringLengthVirtualProperty2()
569+
{
570+
System.Linq.Expressions.Expression<Func<WaybillBase, bool>> filter = x => x.VirtProperty.Length == 24;
571+
572+
var q = Db.From<WaybillBase>().Where(filter);
573+
var target = Db.Select(q);
574+
Assert.AreEqual(3, target.Count);
575+
}
576+
577+
[Test]
578+
public void Can_Where_using_StringLengthVirtualProperty3()
579+
{
580+
System.Linq.Expressions.Expression<Func<WaybillBase, bool>> filter = x => x.VirtProperty.Length == 0 && x.Id > 0;
581+
582+
var q = Db.From<WaybillBase>().Where(filter);
583+
var target = Db.Select(q);
584+
Assert.AreEqual(0, target.Count);
585+
}
586+
587+
[Test]
588+
public void Can_Where_using_StringLengthVirtualProperty4()
589+
{
590+
System.Linq.Expressions.Expression<Func<WaybillBase, bool>> filter = x => x.VirtPropertyNull.Length == 0;
591+
592+
var q = Db.From<WaybillBase>().Where(filter);
593+
var target = Db.Select(q);
594+
Assert.AreEqual(3, target.Count);
595+
}
596+
597+
[Test]
598+
public void Can_Where_using_StringLengthVirtualProperty5()
599+
{
600+
System.Linq.Expressions.Expression<Func<WaybillBase, bool>> filter = x => x.VirtPropertyNull.Length == 0 && x.Id > 0;
601+
602+
var q = Db.From<WaybillBase>().Where(filter);
603+
var target = Db.Select(q);
604+
Assert.AreEqual(3, target.Count);
605+
}
556606
}
557607
}

0 commit comments

Comments
 (0)