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

Commit 388b8c2

Browse files
committed
Add Multiple Self Joins With Nullable Int Ids test
1 parent 8fedda7 commit 388b8c2

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using NUnit.Framework;
2+
using ServiceStack.DataAnnotations;
3+
using ServiceStack.Text;
4+
5+
namespace ServiceStack.OrmLite.Tests.Issues
6+
{
7+
public class ParentSelfRef
8+
{
9+
[AutoIncrement]
10+
public int Id { get; set; }
11+
12+
[References(typeof(ChildSelfRef))]
13+
public int? Child1Id { get; set; }
14+
15+
[Reference]
16+
public ChildSelfRef Child1 { get; set; }
17+
18+
[References(typeof(ChildSelfRef))]
19+
public int? Child2Id { get; set; }
20+
21+
[Reference]
22+
public ChildSelfRef Child2 { get; set; }
23+
}
24+
25+
public class ChildSelfRef
26+
{
27+
[AutoIncrement]
28+
public int Id { get; set; }
29+
public string Name { get; set; }
30+
}
31+
32+
public class MultipleSelfJoinsWithNullableInts : OrmLiteTestBase
33+
{
34+
[Test]
35+
public void Does_support_multiple_self_joins_with_nullable_ints()
36+
{
37+
using (var db = OpenDbConnection())
38+
{
39+
db.DropTable<ParentSelfRef>();
40+
db.DropTable<ChildSelfRef>();
41+
42+
db.CreateTable<ChildSelfRef>();
43+
db.CreateTable<ParentSelfRef>();
44+
45+
var row = new ParentSelfRef
46+
{
47+
Child1 = new ChildSelfRef
48+
{
49+
Name = "Child 1"
50+
},
51+
Child2 = new ChildSelfRef
52+
{
53+
Name = "Child 2"
54+
},
55+
};
56+
57+
db.Save(row, references: true);
58+
59+
row.PrintDump();
60+
61+
Assert.That(row.Id, Is.EqualTo(1));
62+
Assert.That(row.Child1Id, Is.EqualTo(1));
63+
Assert.That(row.Child1.Id, Is.EqualTo(1));
64+
Assert.That(row.Child1.Name, Is.EqualTo("Child 1"));
65+
Assert.That(row.Child2Id, Is.EqualTo(2));
66+
Assert.That(row.Child2.Id, Is.EqualTo(2));
67+
Assert.That(row.Child2.Name, Is.EqualTo("Child 2"));
68+
69+
row = db.LoadSingleById<ParentSelfRef>(row.Id);
70+
71+
Assert.That(row.Id, Is.EqualTo(1));
72+
Assert.That(row.Child1Id, Is.EqualTo(1));
73+
Assert.That(row.Child1.Id, Is.EqualTo(1));
74+
Assert.That(row.Child1.Name, Is.EqualTo("Child 1"));
75+
Assert.That(row.Child2Id, Is.EqualTo(2));
76+
Assert.That(row.Child2.Id, Is.EqualTo(2));
77+
Assert.That(row.Child2.Name, Is.EqualTo("Child 2"));
78+
}
79+
}
80+
}
81+
}

tests/ServiceStack.OrmLite.Tests/ServiceStack.OrmLite.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<Compile Include="Issues\ComplexJoinWithAlias.cs" />
132132
<Compile Include="Issues\CustomFieldTests.cs" />
133133
<Compile Include="Issues\LoadSelectIssue.cs" />
134+
<Compile Include="Issues\MultipleSelfJoinsWithNullableInts.cs" />
134135
<Compile Include="Issues\UtcDateTimeIssueTests.cs" />
135136
<Compile Include="Issues\JoinsWithSchemas.cs" />
136137
<Compile Include="Issues\MappingFieldsFromStoredProcedureTests.cs" />

0 commit comments

Comments
 (0)