This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SQL Server bool condition in JOIN
- Loading branch information
Showing
4 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
tests/ServiceStack.OrmLite.Tests/Issues/JoinBoolSqlServerIssue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Diagnostics; | ||
using NUnit.Framework; | ||
using ServiceStack.DataAnnotations; | ||
using ServiceStack.Text; | ||
|
||
namespace ServiceStack.OrmLite.Tests.Issues | ||
{ | ||
public class JoinBoolSqlServerIssue : OrmLiteTestBase | ||
{ | ||
[Test] | ||
public void Can_Join_on_bool() | ||
{ | ||
using (var db = OpenDbConnection()) | ||
{ | ||
db.DropAndCreateTable<TestType>(); | ||
db.DropAndCreateTable<TestType2>(); | ||
|
||
var q = db.From<TestType>() | ||
.LeftJoin<TestType2>((t1, t2) => t2.BoolCol == true && t1.Id == t2.Id); | ||
var results = db.Select(q); | ||
|
||
q = db.From<TestType>() | ||
.LeftJoin<TestType2>((t1, t2) => t2.NullableBoolCol == true && t1.Id == t2.Id); | ||
results = db.Select(q); | ||
|
||
results.PrintDump(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Can_compare_bool_in_join_expression() | ||
{ | ||
var db = OpenDbConnection(); | ||
|
||
db.DropTable<CardHolder>(); | ||
db.DropTable<Account>(); | ||
|
||
db.CreateTable<Account>(); | ||
db.CreateTable<CardHolder>(); | ||
|
||
var exp1 = db.From<Account>() | ||
.LeftJoin<CardHolder>((a, ch) => a.Id == ch.AccountId && ch.TestBoolB == true); | ||
|
||
Debug.WriteLine(exp1.BodyExpression); | ||
db.Select(exp1).PrintDump(); | ||
|
||
var exp2 = db.From<Account>() | ||
.LeftJoin<CardHolder>((a, ch) => a.Id == ch.AccountId && a.TestBoolA == true); | ||
|
||
Debug.WriteLine(exp2.BodyExpression); | ||
db.Select(exp2).PrintDump(); | ||
|
||
|
||
var exp3 = db.From<Account>() | ||
.Where(a => a.TestBoolA == true); | ||
Debug.WriteLine(exp3.BodyExpression); | ||
db.Select(exp3).PrintDump(); | ||
} | ||
} | ||
|
||
public class Account | ||
{ | ||
[PrimaryKey] | ||
public int Id { get; set; } | ||
|
||
public bool TestBoolA { get; set; } | ||
} | ||
|
||
public class CardHolder | ||
{ | ||
[PrimaryKey] | ||
public int Id { get; set; } | ||
|
||
[References(typeof(Account))] | ||
public int AccountId { get; set; } | ||
|
||
public bool TestBoolB { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters