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

Commit 77e31a3

Browse files
committed
Add example of resetting Seed of new table in SQL Server
1 parent c575202 commit 77e31a3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/ServiceStack.OrmLite.SqlServerTests/InsertParam_GetLastInsertId.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using NUnit.Framework;
66
using ServiceStack.DataAnnotations;
77
using ServiceStack.OrmLite.Dapper;
8+
using ServiceStack.Text;
89

910
namespace ServiceStack.OrmLite.SqlServerTests
1011
{
@@ -68,5 +69,31 @@ public void Can_retrieve_ServerGuid()
6869
Assert.That(insertedRow.Name, Is.EqualTo("foo"));
6970
}
7071
}
72+
73+
[PostCreateTable("DBCC CHECKIDENT (SeedTest, RESEED, 1000)")]
74+
public class SeedTest
75+
{
76+
[AutoIncrement]
77+
public int Id { get; set; }
78+
79+
public string Name { get; set; }
80+
}
81+
82+
[Test]
83+
public void Can_create_table_starting_from_specific_seed()
84+
{
85+
using (var db = OpenDbConnection())
86+
{
87+
db.DropAndCreateTable<SeedTest>();
88+
89+
//var modelDef = typeof(SeedTest).GetModelMetadata();
90+
//var tableName = db.GetDialectProvider().GetQuotedTableName(modelDef);
91+
//db.ExecuteSql($"DBCC CHECKIDENT ({tableName}, RESEED, 1000)");
92+
93+
db.Insert(new SeedTest { Name = "foo" });
94+
95+
Assert.That(db.Select<SeedTest>()[0].Id, Is.EqualTo(1000));
96+
}
97+
}
7198
}
7299
}

0 commit comments

Comments
 (0)