Skip to content

Commit 3509de6

Browse files
committed
feat:修改基本测试命名空间
1 parent fba2c45 commit 3509de6

File tree

1 file changed

+37
-41
lines changed

1 file changed

+37
-41
lines changed
Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
1-
using Microsoft.EntityFrameworkCore;
2-
using Microsoft.Extensions.DependencyInjection;
1+
namespace KingbaseES.BasicTest;
32

4-
namespace KingbaseES.BasicTest
3+
internal static class Program
54
{
6-
internal static class Program
5+
static void Main(string[] args)
76
{
8-
static void Main(string[] args)
9-
{
10-
var services = new ServiceCollection();
7+
var services = new ServiceCollection();
118

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

17-
var serviceProvider = services.BuildServiceProvider();
14+
var serviceProvider = services.BuildServiceProvider();
1815

19-
var context = serviceProvider.GetRequiredService<BlogContext>();
16+
var context = serviceProvider.GetRequiredService<BlogContext>();
2017

21-
context.Database.EnsureCreated();
18+
context.Database.EnsureCreated();
2219

23-
// get list
24-
var blogs = context.Blogs.ToList();
25-
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "当前 Blogs 表中条目数:" + blogs.Count);
26-
if (blogs.Any())
27-
{
28-
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "当前 Blogs 表中条目数大于1,进行清理...");
29-
context.Blogs.RemoveRange(blogs);
30-
context.SaveChanges();
31-
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "清理完成!");
32-
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "当前 Blogs 表中条目数:" + blogs.Count);
33-
}
34-
//add
35-
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "新增 Blog 实体 值为I love EFCore!");
36-
context.Add(new Blog() { Name = "I love EFCore!" });
37-
var result = context.SaveChanges();
38-
39-
//update
40-
var first = context.Blogs.FirstOrDefault();
41-
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "查询结果:" + first.Name);
42-
43-
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "变更 Blog 实体 值为I love EFCore too!");
44-
first.Name = "I love EFCore too!";
20+
// get list
21+
var blogs = context.Blogs.ToList();
22+
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "当前 Blogs 表中条目数:" + blogs.Count);
23+
if (blogs.Any())
24+
{
25+
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "当前 Blogs 表中条目数大于1,进行清理...");
26+
context.Blogs.RemoveRange(blogs);
4527
context.SaveChanges();
46-
47-
// get
48-
var testselect = context.Blogs.FirstOrDefault();
49-
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "查询结果:" + testselect.Name);
50-
Console.ReadKey();
28+
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "清理完成!");
29+
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "当前 Blogs 表中条目数:" + blogs.Count);
5130
}
31+
//add
32+
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "新增 Blog 实体 值为I love EFCore!");
33+
context.Add(new Blog() { Name = "I love EFCore!" });
34+
var result = context.SaveChanges();
35+
36+
//update
37+
var first = context.Blogs.FirstOrDefault();
38+
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "查询结果:" + first.Name);
39+
40+
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "变更 Blog 实体 值为I love EFCore too!");
41+
first.Name = "I love EFCore too!";
42+
context.SaveChanges();
43+
44+
// get
45+
var testselect = context.Blogs.FirstOrDefault();
46+
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "查询结果:" + testselect.Name);
47+
Console.ReadKey();
5248
}
5349
}

0 commit comments

Comments
 (0)