|
12 | 12 | using System.Collections.Generic; |
13 | 13 | using System.Linq; |
14 | 14 | using System.Text; |
| 15 | +using NHibernate.Dialect; |
15 | 16 | using NHibernate.Linq; |
16 | 17 | using NHibernate.DomainModel.Northwind.Entities; |
17 | 18 | using NUnit.Framework; |
@@ -482,13 +483,17 @@ public async Task NullEqualityAsync() |
482 | 483 | await (ExpectAsync(session.Query<User>().Where(o => o.Short == value), Does.Not.Contain("is null").IgnoreCase.And.Not.Contain("cast"))); |
483 | 484 | await (ExpectAsync(session.Query<User>().Where(o => value == o.Short), Does.Not.Contain("is null").IgnoreCase.And.Not.Contain("cast"))); |
484 | 485 |
|
485 | | - await (ExpectAsync(session.Query<User>().Where(o => o.NullableShort == 3), Does.Not.Contain("is null").IgnoreCase.And.Contain("cast"))); |
486 | | - await (ExpectAsync(session.Query<User>().Where(o => 3 == o.NullableShort), Does.Not.Contain("is null").IgnoreCase.And.Contain("cast"))); |
487 | | - |
488 | | - await (ExpectAsync(session.Query<User>().Where(o => o.NullableShort.Value == 3), Does.Not.Contain("is null").IgnoreCase.And.Contain("cast"))); |
489 | | - await (ExpectAsync(session.Query<User>().Where(o => 3 == o.NullableShort.Value), Does.Not.Contain("is null").IgnoreCase.And.Contain("cast"))); |
490 | | - await (ExpectAsync(session.Query<User>().Where(o => o.Short == 3), Does.Not.Contain("is null").IgnoreCase.And.Contain("cast"))); |
491 | | - await (ExpectAsync(session.Query<User>().Where(o => 3 == o.Short), Does.Not.Contain("is null").IgnoreCase.And.Contain("cast"))); |
| 486 | + var shouldCast = Sfi.Dialect is SQLiteDialect || // transparent cast is translated to sql |
| 487 | + Sfi.Dialect.TryGetCastTypeName(NHibernateUtil.Int16.SqlType, out var shortCast) && |
| 488 | + Sfi.Dialect.TryGetCastTypeName(NHibernateUtil.Int32.SqlType, out var intCast) && |
| 489 | + shortCast != intCast; |
| 490 | + await (ExpectAsync(session.Query<User>().Where(o => o.NullableShort == 3), shouldCast ? WithoutIsNullAndWithCast() : WithoutIsNullAndWithoutCast())); |
| 491 | + await (ExpectAsync(session.Query<User>().Where(o => 3 == o.NullableShort), shouldCast ? WithoutIsNullAndWithCast() : WithoutIsNullAndWithoutCast())); |
| 492 | + |
| 493 | + await (ExpectAsync(session.Query<User>().Where(o => o.NullableShort.Value == 3), shouldCast ? WithoutIsNullAndWithCast() : WithoutIsNullAndWithoutCast())); |
| 494 | + await (ExpectAsync(session.Query<User>().Where(o => 3 == o.NullableShort.Value), shouldCast ? WithoutIsNullAndWithCast() : WithoutIsNullAndWithoutCast())); |
| 495 | + await (ExpectAsync(session.Query<User>().Where(o => o.Short == 3), shouldCast ? WithoutIsNullAndWithCast() : WithoutIsNullAndWithoutCast())); |
| 496 | + await (ExpectAsync(session.Query<User>().Where(o => 3 == o.Short), shouldCast ? WithoutIsNullAndWithCast() : WithoutIsNullAndWithoutCast())); |
492 | 497 | } |
493 | 498 |
|
494 | 499 | [Test] |
@@ -586,6 +591,38 @@ public async Task NullInequalityAsync() |
586 | 591 | await (ExpectAsync(session.Query<User>().Where(o => value != o.NullableShort.Value), Does.Contain("is null").IgnoreCase.And.Not.Contain("cast"))); |
587 | 592 | await (ExpectAsync(session.Query<User>().Where(o => o.Short != value), Does.Not.Contain("is null").IgnoreCase.And.Not.Contain("cast"))); |
588 | 593 | await (ExpectAsync(session.Query<User>().Where(o => value != o.Short), Does.Not.Contain("is null").IgnoreCase.And.Not.Contain("cast"))); |
| 594 | + |
| 595 | + var shouldCast = Sfi.Dialect is SQLiteDialect || // transparent cast is translated to sql |
| 596 | + Sfi.Dialect.TryGetCastTypeName(NHibernateUtil.Int16.SqlType, out var shortCast) && |
| 597 | + Sfi.Dialect.TryGetCastTypeName(NHibernateUtil.Int32.SqlType, out var intCast) && |
| 598 | + shortCast != intCast; |
| 599 | + await (ExpectAsync(session.Query<User>().Where(o => o.NullableShort != 3), shouldCast ? WithIsNullAndWithCast() : WithIsNullAndWithoutCast())); |
| 600 | + await (ExpectAsync(session.Query<User>().Where(o => 3 != o.NullableShort), shouldCast ? WithIsNullAndWithCast() : WithIsNullAndWithoutCast())); |
| 601 | + |
| 602 | + await (ExpectAsync(session.Query<User>().Where(o => o.NullableShort.Value != 3), shouldCast ? WithIsNullAndWithCast() : WithIsNullAndWithoutCast())); |
| 603 | + await (ExpectAsync(session.Query<User>().Where(o => 3 != o.NullableShort.Value), shouldCast ? WithIsNullAndWithCast() : WithIsNullAndWithoutCast())); |
| 604 | + await (ExpectAsync(session.Query<User>().Where(o => o.Short != 3), shouldCast ? WithoutIsNullAndWithCast() : WithoutIsNullAndWithoutCast())); |
| 605 | + await (ExpectAsync(session.Query<User>().Where(o => 3 != o.Short), shouldCast ? WithoutIsNullAndWithCast() : WithoutIsNullAndWithoutCast())); |
| 606 | + } |
| 607 | + |
| 608 | + private IResolveConstraint WithIsNullAndWithoutCast() |
| 609 | + { |
| 610 | + return Does.Contain("is null").IgnoreCase.And.Not.Contain("cast").IgnoreCase; |
| 611 | + } |
| 612 | + |
| 613 | + private IResolveConstraint WithIsNullAndWithCast() |
| 614 | + { |
| 615 | + return Does.Contain("is null").IgnoreCase.And.Contain("cast").IgnoreCase; |
| 616 | + } |
| 617 | + |
| 618 | + private IResolveConstraint WithoutIsNullAndWithoutCast() |
| 619 | + { |
| 620 | + return Does.Not.Contain("is null").IgnoreCase.And.Not.Contain("cast").IgnoreCase; |
| 621 | + } |
| 622 | + |
| 623 | + private IResolveConstraint WithoutIsNullAndWithCast() |
| 624 | + { |
| 625 | + return Does.Not.Contain("is null").IgnoreCase.And.Contain("cast").IgnoreCase; |
589 | 626 | } |
590 | 627 |
|
591 | 628 | [Test] |
|
0 commit comments