entityframwork codeFirst

codeFirst

1、添加MySql.Data、MySql.Data.Entity的引用。

2、添加entityframwork引用。

3、数据库连接。

 [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
    public class BookContext : DbContext
    {
        public BookContext() : base("name=BookContext") { }


        public DbSet<Book> Book { get; set; }
    }
public class Book
    {
     [Key]
public int ID { get; set; } public string Name { get; set; } public DateTime ReleaseDate { get; set; } public string Author { get; set; } public decimal Price { get; set; } }

4、Add-Migration 

5、Update-Database

原文地址:https://www.cnblogs.com/KQNLL/p/9897859.html