• 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. cocos jsb工程转html 工程

    1 CCBoot.js prepare方法:注掉下面这行,先加载moduleConfig中的脚本后加载user脚本 //newJsList = newJsList.concat(jsList); // ...

  2. 关于传统项目打成war包的的分析

    技术在不断的革新,以前的项目没有jar管理工具时,都是手动将依赖的jar拷贝到项目之下,然后Build Path,之后Maven出现了,出现了jar包中央仓库,所有的jar包资源集中在这里,免去频繁去 ...

  3. 关于syslog日志功能详解 事件日志分析、EventLog Analyzer

    关于syslog日志功能详解 事件日志分析.EventLog Analyzer 一.日志管理 保障网络安全 Windows系统日志分析 Syslog日志分析 应用程序日志分析 Windows终端服务器 ...

  4. CentOS Linux更改MySQL数据库目录位置具体操作

    引言: 由于MySQL的数据库太大,默认安装的/var盘已经再也无法容纳新增加的数据,没有办法,只能想办法转移数据的目录. 下面我整理一下把MySQL从/var/lib/mysql目录下面转移到/ho ...

  5. presentation skills

    下面是从一个网站摘录下来的关于presentation skill需要回答的14个问题:网站的地址为:http://www.mindtools.com/pages/article/newCS_96.h ...

  6. c# 二维list排序和计时

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...

  7. c# 抽象类和抽象方法

    参考:http://www.runoob.com/csharp/csharp-polymorphism.html https://zhidao.baidu.com/question/587686949 ...

  8. python3.4读取excel数据绘图

    #!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ pyt ...

  9. 第02章:MongoDB安装

    ①下载 https://www.mongodb.com/  下载所需版本的tar.gz ②解压安装 tar -zxvf mongodb-3.2.12.tar.gz mv -r mongodb-3.2. ...

  10. css 兼容ie8 rgba()用法

    今天遇到了一个问题,要在一个页面中设置一个半透明的白色div.这个貌似不是难题,只需要给这个div设置如下的属性即可: background: rgba(255,255,255,.1); 但是要兼容到 ...