Skip to content

Commit 8c7d53e

Browse files
committed
feat:待测试迁移
1 parent 857b554 commit 8c7d53e

File tree

7 files changed

+158
-2
lines changed

7 files changed

+158
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class BlogContext : DbContext
2121
public DbSet<Blog> Blogs { get; set; }
2222

2323
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
24-
=> optionsBuilder.UseKdbndp(@"host={host};port={port};database={database};user id={username};password={password};");
24+
=> optionsBuilder.UseKdbndp(@"host={host};port={port};database={database};username={username};password={password};");
2525
}
2626

2727
public class Blog
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Design;
3+
4+
namespace KingbaseES.BasicTest
5+
{
6+
public class BlogContextFactory : IDesignTimeDbContextFactory<BlogContext>
7+
{
8+
public BlogContext CreateDbContext(string[] args)
9+
{
10+
var optionsBuilder = new DbContextOptionsBuilder<BlogContext>();
11+
optionsBuilder.UseKdbndp("host=localhost;port=54321;database=test;username=system;password=123456;");
12+
13+
return new BlogContext(optionsBuilder.Options);
14+
}
15+
}
16+
}

test/KingbaseES.BasicTest/KingbaseES.BasicTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Microsoft.EntityFrameworkCore" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design"/>
1112
</ItemGroup>
1213

1314
<ItemGroup>

test/KingbaseES.BasicTest/Migrations/20231013152623_initial.Designer.cs

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace KingbaseES.BasicTest.Migrations
6+
{
7+
public partial class initial : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.CreateSequence(
12+
name: "tests_id_seq",
13+
minValue: 1L,
14+
maxValue: 9223372036854775807L);
15+
16+
migrationBuilder.CreateTable(
17+
name: "blogs",
18+
columns: table => new
19+
{
20+
id = table.Column<int>(type: "integer", nullable: false, defaultValueSql: "nextval('tests_id_seq'::regclass)"),
21+
name = table.Column<string>(type: "text", nullable: true)
22+
},
23+
constraints: table =>
24+
{
25+
table.PrimaryKey("PK_blogs", x => x.id);
26+
});
27+
}
28+
29+
protected override void Down(MigrationBuilder migrationBuilder)
30+
{
31+
migrationBuilder.DropTable(
32+
name: "blogs");
33+
34+
migrationBuilder.DropSequence(
35+
name: "tests_id_seq");
36+
}
37+
}
38+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// <auto-generated />
2+
using Kdbndp.EntityFrameworkCore.KingbaseES.Metadata;
3+
using KingbaseES.BasicTest;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Infrastructure;
6+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7+
8+
#nullable disable
9+
10+
namespace KingbaseES.BasicTest.Migrations
11+
{
12+
[DbContext(typeof(BlogContext))]
13+
partial class BlogContextModelSnapshot : ModelSnapshot
14+
{
15+
protected override void BuildModel(ModelBuilder modelBuilder)
16+
{
17+
#pragma warning disable 612, 618
18+
modelBuilder
19+
.HasAnnotation("ProductVersion", "6.0.22")
20+
.HasAnnotation("Relational:MaxIdentifierLength", 63);
21+
22+
KdbndpModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
23+
24+
modelBuilder.HasSequence("tests_id_seq")
25+
.HasMin(1L)
26+
.HasMax(9223372036854775807L);
27+
28+
modelBuilder.Entity("KingbaseES.BasicTest.Blog", b =>
29+
{
30+
b.Property<int>("Id")
31+
.ValueGeneratedOnAdd()
32+
.HasColumnType("integer")
33+
.HasColumnName("id")
34+
.HasDefaultValueSql("nextval('tests_id_seq'::regclass)");
35+
36+
b.Property<string>("Name")
37+
.HasColumnType("text")
38+
.HasColumnName("name");
39+
40+
b.HasKey("Id");
41+
42+
b.ToTable("blogs");
43+
});
44+
#pragma warning restore 612, 618
45+
}
46+
}
47+
}

test/KingbaseES.BasicTest/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ static void Main(string[] args)
99
{
1010
var services = new ServiceCollection();
1111

12-
services.AddDbContext<BlogContext>(options => options.UseKdbndp(@"host=localhost;port=54321;database=test;user id=system;password=123456;"));
12+
services.AddDbContext<BlogContext>(options =>
13+
{
14+
options.UseKdbndp(@"host=localhost;port=54321;database=test;user id=system;password=123456;");
15+
});
1316

1417
var serviceProvider = services.BuildServiceProvider();
1518

1619
var context = serviceProvider.GetRequiredService<BlogContext>();
1720

21+
context.Database.EnsureCreated();
22+
1823
// get list
1924
var blogs = context.Blogs.ToList();
2025

0 commit comments

Comments
 (0)