You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
using EFCore7Study.DataService;
|
|
|
|
|
|
|
|
using Spectre.Console;
|
|
|
|
|
|
|
|
namespace EFCore7Study.CoreConsoleApp
|
|
|
|
{
|
|
|
|
internal class Program
|
|
|
|
{
|
|
|
|
static void Main(string[] args)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ShowQuery()
|
|
|
|
{
|
|
|
|
AnsiConsole.Status()
|
|
|
|
.Spinner(Spinner.Known.Balloon)
|
|
|
|
.Start("准备查询数据库...", ctx =>
|
|
|
|
{
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
|
|
|
// 生成查询对象
|
|
|
|
ctx.Status("生成查询对象...");
|
|
|
|
AppDbContext dbContext = new AppDbContext();
|
|
|
|
//Thread.Sleep(2000);
|
|
|
|
AnsiConsole.MarkupLine("生成查询对象: DbContext, 完成!");
|
|
|
|
|
|
|
|
// 连接数据库
|
|
|
|
ctx.Status("正在连接到数据库服务器...");
|
|
|
|
ctx.Spinner(Spinner.Known.Balloon);
|
|
|
|
ctx.SpinnerStyle(Style.Parse("green"));
|
|
|
|
//Thread.Sleep(2000);
|
|
|
|
AnsiConsole.MarkupLine("已连接到数据库服务器!");
|
|
|
|
|
|
|
|
|
|
|
|
// 查询数据
|
|
|
|
ctx.Status("正在查询数据...");
|
|
|
|
ctx.Spinner(Spinner.Known.Star2);
|
|
|
|
ctx.SpinnerStyle(Style.Parse("yellow"));
|
|
|
|
//Thread.Sleep(3000);
|
|
|
|
AnsiConsole.MarkupLine("完成查询!");
|
|
|
|
|
|
|
|
|
|
|
|
//输出查询结果
|
|
|
|
ctx.Status("输出查询结果...");
|
|
|
|
ctx.Spinner(Spinner.Known.Arrow);
|
|
|
|
ctx.SpinnerStyle(Style.Parse("red"));
|
|
|
|
|
|
|
|
dbContext.Accounts.ToList().ForEach(x =>
|
|
|
|
{
|
|
|
|
AnsiConsole.MarkupLine($"标识:{x.Id},编号:{x.Code}, 姓名:{x.Name.PadRight(10)},年龄:{x.Age}, 密码:{x.Pwd}");
|
|
|
|
Thread.Sleep(300);
|
|
|
|
});
|
|
|
|
|
|
|
|
AnsiConsole.MarkupLine("任务完成!");
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|