.Net Code 基础数据迁移与配置跨域
数据迁移
1.添加引用:
2.创建上下文
public appDbContex(DbContextOptions<appDbContex> option) : base(option) { } public DbSet<Student> students { get; set; } public DbSet<ClassInfo> classInfos { get; set; }
3.Startup中添加上下文:
services.AddDbContext<AppDbConetext>(option => { option.UseSqlServer(Configuration.GetConnectionString("MSSQL")); });
4.appsettings 配置链接数据库:
"ConnectionStrings": { "MSSQL": "Data Source=.;Initial Catalog=Work10.12;Integrated Security=True"
5.程序包管理器控制台:
add-migration v1
update-database
跨域
services.AddCors(option => { option.AddDefaultPolicy(p => { p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); }); });