mvc core 增删改查

asp.net core Mvc 增删改查

 

1.创建项目

 

创建Data文件夹

创建实体类Students/cs

复制代码
  public class Students
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
    }
复制代码

 

创建MyDbContext

复制代码
  public class MyDbContext:DbContext
    {
        public MyDbContext(DbContextOptions<MyDbContext> options):base(options)
        {

        }

        public DbSet<Students> Students { get; set; }
    }
复制代码

 

 

 在appsetting.json配置连接字符串

 

 

复制代码
{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "ConnectionStrings": {
    "DefaultConnection": "server=.;database=Students;uid=sa;pwd=123456;"
  }
}
复制代码

使用 code first 创建数据库

 

 

输入命名

 Add-Migration init

 

posted @ 2021-03-10 14:30  厦门哈韩  阅读(185)  评论(0编辑  收藏  举报