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

Commit 41d3a72

Browse files
committed
Add ParentChildCyclicalExample test
1 parent c8745eb commit 41d3a72

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
<Compile Include="UseCase\CustomerOrdersUseCase.cs" />
255255
<Compile Include="UseCase\FieldFromInterfaceImplementationUseCase.cs" />
256256
<Compile Include="UseCase\NestedComplexTypeUseCase.cs" />
257+
<Compile Include="UseCase\ParentChildCyclicalExample.cs" />
257258
<Compile Include="UseCase\SchemaUseCase.cs" />
258259
<Compile Include="UseCase\ServiceStack_OrmLite_UseCase.cs" />
259260
<Compile Include="UseCase\ShardingUseCase.cs" />
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
using ServiceStack.DataAnnotations;
4+
using ServiceStack.Text;
5+
6+
namespace ServiceStack.OrmLite.Tests.UseCase
7+
{
8+
public class Parent
9+
{
10+
[AutoIncrement]
11+
public int Id { get; set; }
12+
13+
public string Name { get; set; }
14+
15+
// the item currently published, modelled like an EF navigation property
16+
[Reference]
17+
public Child ActiveChild { get; set; }
18+
19+
public int? ActiveChildId { get; set; }
20+
21+
// all items mapped to this Parent
22+
[Reference]
23+
public List<Child> AllChildren { get; set; }
24+
}
25+
26+
public class Child
27+
{
28+
[AutoIncrement]
29+
public int Id { get; set; }
30+
31+
public int ParentId { get; set; }
32+
33+
public string Description { get; set; }
34+
}
35+
36+
public class ParentChildCyclicalExample : OrmLiteTestBase
37+
{
38+
[Test]
39+
public void Can_create_Parent_Child_Tables()
40+
{
41+
using (var db = OpenDbConnection())
42+
{
43+
db.DropAndCreateTable<Parent>();
44+
db.DropAndCreateTable<Child>();
45+
46+
var parent = new Parent
47+
{
48+
Name = "Parent",
49+
ActiveChild = new Child { Description = "Active" },
50+
AllChildren = new List<Child>
51+
{
52+
new Child { Description = "Child 1" },
53+
new Child { Description = "Child 2" },
54+
}
55+
};
56+
57+
db.Save(parent, references:true);
58+
59+
var dbParent = db.LoadSelect<Parent>()[0];
60+
dbParent.PrintDump();
61+
62+
Assert.That(dbParent.ActiveChild, Is.Not.Null);
63+
Assert.That(dbParent.AllChildren.Count, Is.EqualTo(3));
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)