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

Commit 5b7d6c4

Browse files
committed
Add test showing sub expression working when called inside a data model
1 parent fd33a39 commit 5b7d6c4

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Data;
3+
using System.Linq;
24
using NUnit.Framework;
35
using ServiceStack.DataAnnotations;
46
using ServiceStack.Logging;
@@ -104,5 +106,62 @@ public void Can_reference_variable_in_sub_expression()
104106
Assert.That(expr.ToSelectStatement().NormalizeSql(), Is.StringContaining("@0"));
105107
}
106108
}
109+
110+
public class AnyObjectClass
111+
{
112+
public Guid? Identity { get; set; }
113+
114+
public string Name { get; set; }
115+
116+
public IDbConnection db;
117+
118+
[DataAnnotations.Ignore]
119+
public decimal CustomProperty
120+
{
121+
get
122+
{
123+
return db.Select<AnyObjectClassItem>
124+
(s => Sql.In(s.Identity,
125+
db.From<AnyObjectClassItem>()
126+
.Where(b => b.AnyObjectClassId == this.Identity)
127+
.Select(b => b.Identity))
128+
).Sum(r => r.PurchasePrice);
129+
}
130+
}
131+
}
132+
133+
public class AnyObjectClassItem
134+
{
135+
public Guid? Identity { get; set; }
136+
137+
public string Name { get; set; }
138+
139+
public decimal PurchasePrice { get; set; }
140+
141+
[ForeignKey(typeof(AnyObjectClass))]
142+
public Guid AnyObjectClassId { get; set; }
143+
144+
public AnyObjectClass AnyObjectClass { get; set; }
145+
}
146+
147+
[Test]
148+
public void Can_select_sub_expression_when_called_within_a_datamodel()
149+
{
150+
using (var db = OpenDbConnection())
151+
{
152+
db.DropTable<AnyObjectClassItem>();
153+
db.DropTable<AnyObjectClass>();
154+
db.CreateTable<AnyObjectClass>();
155+
db.CreateTable<AnyObjectClassItem>();
156+
157+
var model = new AnyObjectClass { db = db };
158+
var result = model.CustomProperty;
159+
160+
db.GetLastSql().Print();
161+
162+
result.PrintDump();
163+
}
164+
}
165+
107166
}
108167
}

0 commit comments

Comments
 (0)