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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM