• Create a new project named MySqlTest

  • Install following packages by right-clicking on the References folder of the project and selecting Manage NuGet Packages...

    • EntityFramework
    • MySql.Data
    • MySql.data.Entity
  • Update the app.config file

  • Add a model and the DbContext

      public class User
    {
    public int UserId { get; set; } public string Name { get; set; }
    } public class MyDb:DbContext
    {
    public MyDb():base("name=TestDb")
    { } public DbSet<User> Users { get; set; }
    }
  • Add some Test Codes

     static void Main(string[] args)
    {
    using (MyDb db = new MyDb())
    {
    User u = new User { Name = "Joey"};
    db.Users.Add(u);
    db.SaveChanges();
    } Console.ReadLine();
    }
  • Compile the project

  • Enable migrations

    Run the Enable-Migrations command in Package Manager Console

  • Add the first Migration

    Run the Add-Migration init command in Package Manager Console

  • Update Database

    Run the Update-Database command in Package Manager Console

  • To check whether the table named users is created

  • Run the Projcet and check is there any data have been inserted

Lerning Entity Framework 6 ------ A demo of using Entity framework with MySql的更多相关文章

  1. Visual Studio2017中如何让Entity Framework工具【ADO.NET实体数据模型】支持MYSQL数据源

    熟悉Entity Framework应该对以下图片不陌生,他就是ADO.NET实体数据模型向导:可以将数据库的表自动生成模型类,或者创建Code First的模型文件. 但是这个模型向导默认只显示微软 ...

  2. Entity Framework入门教程:什么是Entity Framework

    Entity Framework简介 Entity Framework是微软提供的一个O/RM(对象关系映射)框架.它基于ADO.NET,为开发人员提供了一种自动化的机制来访问和存储数据库中的数据. ...

  3. Please set registry key HKLM\Microsoft\.NET Framework\InstallRoot to point to the .NET Framework

    安装.NET程序时会提示“Please set registry key HKLM\Microsoft\.NET Framework\InstallRoot to point to the .NET ...

  4. lua模块demo(redis,http,mysql,cjson,本地缓存)

    1. lua模块demo(redis,http,mysql,cjson,本地缓存) 1.1. 配置 在nginx.conf中设置lua_shared_dict my_cache 128m; 开启ngi ...

  5. java.lang.NoSuchMethodError: org.apache.curator.framework.api.CreateBuilder.creatingParentsIfNeeded()Lorg/apache/curator/framework/api/ProtectACLCreateModeStatPathAndBytesable;

    1 错误信息 java.lang.NoSuchMethodError: org.apache.curator.framework.api.CreateBuilder.creatingParentsIf ...

  6. Attaching an entity of type 'xxx' failed because another entity of the same type already has the same primary key value.

    问题的详细描述: Attaching an entity of type 'xxxxx' failed because another entity of the same type already ...

  7. Mvc5+Entity Framework6 之二----在MVC中用Entity Framework实现基本的CRUD

    目标:创建控制器和视图的代码,实现CRUD(创建,读取,更新,删除)功能 创建一个详细信息页 控制器为Students的Index页生成的代码排除Enrollments属性在外,因为该属性中关联着一个 ...

  8. Entity Framework Core系列之什么是Entity Framework Core

    前言 Entity Framework Core (EF Core)是微软推荐的基于.NET Core framework的应用程序数据访问技术.它是轻量级,可扩展并且支持跨平台开发.EF Core是 ...

  9. 如何修改Entity Framework Db Frist模式下的Entity继承关系?

    1.准备工作 Db Frist创建实体数据模型(创建edmx并不是重点,各位随意即可),此处取名ZeroCodeDB,所得文件如图所示:其中红框中的文件(ZeroCodeDB.tt)是各实体的生成的关 ...

随机推荐

  1. VB.NET and C# 差异

    VB.NET Program Structure C# Imports System Namespace Hello    Class HelloWorld       Overloads Share ...

  2. HDU3695(AC自动机模板题)

    题意:给你n个字符串,再给你一个大的字符串A,问你着n个字符串在正的A和反的A里出现多少个? 其实就是AC自动机模板题啊( ╯□╰ ) 正着query一次再反着query一次就好了 /* gyt Li ...

  3. 如何使用GCC生成动态库和静态库

    根据链接时期的不同,库又有静态库和动态库之分.静态库是在链接阶段被链接的,所以生成的可执行文件就不受库的影响,即使库被删除,程序依然可以成功运行.而动态库是在程序执行的时候被链接的.程序执行完,库仍需 ...

  4. Django之url定义和ORM框架的使用

    前言,Django安装 pip install django # 官网安装最新版本 pip install django -i "https://pypi.doubanio.com/simp ...

  5. java web 大总结

    C/s架构:        socket.serversocket.awt/swing做一个客户端软件        建好socket连接后,通过IO流交换数据.数据格式由各个开发者自己确定,B/C架 ...

  6. MacBook小技巧

    退出全屏:Control+Command+F.关闭当前的应用程序:Command+W.退出应用程序,可对着Dock上的应用程序辅助点按(右键),选择退出.也可直接按Commnad+Q退出当前的应用程序 ...

  7. Linux服务器上新增开放端口号

    开放端口的方法: 方法一:命令行方式               1. 开放端口命令: /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT    ...

  8. springboot深入学习(一)-----springboot核心、配置文件加载、日志配置

    一.@SpringBootApplication @SpringBootApplication是spring boot的核心注解,源码如下: 相当于:@Configuration+@EnableAut ...

  9. TCP/IP协议(3):数据链路层

    OSI数据链路层上的协议有Ethernet/IEEE802.3/IEEE802.4/IEEE802.5. ARP.RARP等. 1.Ethernet(以太网) 链路层支持很多协议,比如Ethernet ...

  10. base64编码理解

    原文地址:http://www.ruanyifeng.com/blog/2008/06/base64.html 所谓Base64,就是说选出64个字符----小写字母a-z.大写字母A-Z.数字0-9 ...