项目地址
dbt
airflow
一、创建一个Razor项目
1.1 创建项目
- 创建一个razor项目
1.2 创建项目所需文件夹
- 与MVC不同的是,Razor项目没有Controller
1.3 配置项目
appsettings.json
里面配置数据库链接
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Server=.;Database=netdemo_Razor;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;"
}
}
program.cs
页面里添加EF中间件
builder.Services.AddRazorPages();
builder.Services.AddDbContext<ApplicationDBContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
var app = builder.Build();
- 配置
Data/ApplicationDBContext.cs
namespace RazorDemo.Data
{
public class ApplicationDBContext : DbContext
{
public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)
{
}
public DbSet<Category> Categories {
get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.