|
1 | 1 | using System;
|
2 | 2 | using System.Data;
|
3 | 3 | using System.Linq;
|
| 4 | +using System.Linq.Expressions; |
4 | 5 | using NUnit.Framework;
|
5 | 6 | using ServiceStack.DataAnnotations;
|
6 | 7 | using ServiceStack.Logging;
|
| 8 | +using ServiceStack.OrmLite.SqlServer; |
7 | 9 | using ServiceStack.Text;
|
8 | 10 |
|
9 | 11 | namespace ServiceStack.OrmLite.Tests.Issues
|
@@ -238,6 +240,45 @@ public void SubExpressions_TestMethod3()
|
238 | 240 | w.TestMethod3();
|
239 | 241 | }
|
240 | 242 | }
|
| 243 | + |
| 244 | + [Test] |
| 245 | + public void SubExpressions_with_CustomSqlExpression_and_merging_multiple_predicates() |
| 246 | + { |
| 247 | + var db = new OrmLiteConnection(new OrmLiteConnectionFactory("test", new CustomSqlServerDialectProvider())); |
| 248 | + |
| 249 | + var q = db.From<MarginItem>().Where(s => Sql.In(s.Identity, |
| 250 | + db.From<WaybillItem>() |
| 251 | + .Where(w => Sql.In(w.WaybillId, |
| 252 | + db.From<Waybill>() |
| 253 | + .Where(bb => bb.Identity == null) |
| 254 | + .And(bb => bb.Name == "test") |
| 255 | + .Select(ww => ww.Identity)) |
| 256 | + ) |
| 257 | + .Select(b => b.MarginItemId))); |
| 258 | + |
| 259 | + Assert.That(q.ToSelectStatement().NormalizeSql(), Is.StringContaining("@")); |
| 260 | + } |
| 261 | + } |
| 262 | + |
| 263 | + class CustomSqlExpression<T> : SqlServerExpression<T> |
| 264 | + { |
| 265 | + private Expression<Func<T, bool>> _whereExpression; |
| 266 | + |
| 267 | + public CustomSqlExpression(IOrmLiteDialectProvider dialectProvider) : base(dialectProvider) {} |
| 268 | + |
| 269 | + public override SqlExpression<T> And(Expression<Func<T, bool>> predicate) |
| 270 | + { |
| 271 | + _whereExpression = _whereExpression == null ? predicate : predicate.And(_whereExpression); |
| 272 | + return base.And(predicate); |
| 273 | + } |
| 274 | + } |
| 275 | + |
| 276 | + class CustomSqlServerDialectProvider : SqlServerOrmLiteDialectProvider |
| 277 | + { |
| 278 | + public override SqlExpression<T> SqlExpression<T>() |
| 279 | + { |
| 280 | + return new CustomSqlExpression<T>(this); |
| 281 | + } |
241 | 282 | }
|
242 | 283 |
|
243 | 284 | public class WaybillItem : BaseObject
|
|
0 commit comments