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

Commit d02367f

Browse files
committed
Add example of modifying column behavior at runtime
1 parent 45d0183 commit d02367f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tests/ServiceStack.OrmLite.Tests/OrmLiteSaveTests.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void Save_populates_AutoIncrementId()
1515
{
1616
using (var db = OpenDbConnection())
1717
{
18-
db.CreateTable<PersonWithAutoId>(overwrite: true);
18+
db.DropAndCreateTable<PersonWithAutoId>();
1919

2020
var row = new PersonWithAutoId
2121
{
@@ -30,6 +30,33 @@ public void Save_populates_AutoIncrementId()
3030
}
3131
}
3232

33+
[Test]
34+
public void Can_disable_AutoIncrement_field()
35+
{
36+
using (var db = OpenDbConnection())
37+
{
38+
db.DropAndCreateTable<PersonWithAutoId>();
39+
40+
typeof(PersonWithAutoId)
41+
.GetModelMetadata()
42+
.PrimaryKey.AutoIncrement = false;
43+
44+
var row = new PersonWithAutoId
45+
{
46+
Id = 100,
47+
FirstName = "Jimi",
48+
LastName = "Hendrix",
49+
Age = 27
50+
};
51+
52+
db.Insert(row);
53+
54+
row = db.SingleById<PersonWithAutoId>(100);
55+
56+
Assert.That(row.Id, Is.EqualTo(100));
57+
}
58+
}
59+
3360
[Test]
3461
public void SaveAll_populates_AutoIncrementId()
3562
{

0 commit comments

Comments
 (0)