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

Commit 46d4168

Browse files
committed
Add non-convention PK References test
1 parent e1bf81e commit 46d4168

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
using ServiceStack.DataAnnotations;
4+
using ServiceStack.Text;
5+
6+
namespace ServiceStack.OrmLite.Tests.Issues
7+
{
8+
public class Root
9+
{
10+
[PrimaryKey]
11+
public int RootId { get; set; }
12+
13+
[Reference]
14+
public List<RootItem> Items { get; set; }
15+
}
16+
17+
public class RootItem
18+
{
19+
[PrimaryKey]
20+
public int RootItemId { get; set; }
21+
22+
public int RootId { get; set; } //`{Parent}Id` convention to refer to Client
23+
24+
public string MyValue { get; set; }
25+
}
26+
27+
public class LoadReferencesForeignKeyTests : OrmLiteTestBase
28+
{
29+
[Test]
30+
public void Does_populate_Ref_Ids_of_non_convention_PrimaryKey_Tables()
31+
{
32+
using (var db = OpenDbConnection())
33+
{
34+
db.DropAndCreateTable<Root>();
35+
db.DropAndCreateTable<RootItem>();
36+
37+
var root = new Root {
38+
RootId = 1,
39+
Items = new List<RootItem> {
40+
new RootItem { RootItemId = 2, MyValue = "x" }
41+
}
42+
};
43+
44+
db.Save(root, references: true);
45+
46+
Assert.That(root.Items[0].RootId, Is.EqualTo(root.RootId));
47+
}
48+
}
49+
}
50+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<Compile Include="Issues\CsvTests.cs" />
142142
<Compile Include="Issues\CustomFieldTests.cs" />
143143
<Compile Include="Issues\LoadReferencesCaseSensitiveTest.cs" />
144+
<Compile Include="Issues\LoadReferencesForeignKeyTests.cs" />
144145
<Compile Include="Issues\LoadSelectIssue.cs" />
145146
<Compile Include="Issues\MultipleSelfJoinsWithNullableInts.cs" />
146147
<Compile Include="Issues\SelectScalarTests.cs" />

0 commit comments

Comments
 (0)