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