EntityFramework Core 6.0 MySql WebApi

Microsoft.EntityFrameworkCore

Microsoft.EntityFrameworkCore.Design

Pomelo.EntityFrameworkCore.MySql

Microsoft.EntityFrameworkCore.Tools

------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
  public class Course
  {
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int CourseID { get; set; }
    public string Title { get; set; }
    public int Credits { get; set; }

    public ICollection<Enrollment> Enrollments { get; set; }
  }
}

---------------------------------------------------------------------------------------------------------------------------------------

using Microsoft.EntityFrameworkCore;

namespace Model
{
  public class SchoolContext : DbContext
  {
    public SchoolContext(DbContextOptions<SchoolContext> options) : base(options)
    {
    }

    public DbSet<Student> Students { get; set; }
    public DbSet<Enrollment> Enrollments { get; set; }
    public DbSet<Course> Courses { get; set; }

    //protected override void OnModelCreating(ModelBuilder modelBuilder)
    //{
    // //modelBuilder.Entity<Course>().ToTable("Course");
    // //modelBuilder.Entity<Enrollment>().ToTable("Enrollment");
    // //modelBuilder.Entity<Student>().ToTable("Student");
    //}
  }
}

命令

Add-Migration

update-database

posted @   Ken-Cai  阅读(51)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2013-05-12 Silverlight 验证的一个注意事项
点击右上角即可分享
微信分享提示