Lerning Entity Framework 6 ------ A demo of using Entity framework with MySql
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 ConsoleAdd the first Migration
Run the Add-Migration init command in Package Manager ConsoleUpdate Database
Run the Update-Database command in Package Manager ConsoleTo 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的更多相关文章
- Visual Studio2017中如何让Entity Framework工具【ADO.NET实体数据模型】支持MYSQL数据源
熟悉Entity Framework应该对以下图片不陌生,他就是ADO.NET实体数据模型向导:可以将数据库的表自动生成模型类,或者创建Code First的模型文件. 但是这个模型向导默认只显示微软 ...
- Entity Framework入门教程:什么是Entity Framework
Entity Framework简介 Entity Framework是微软提供的一个O/RM(对象关系映射)框架.它基于ADO.NET,为开发人员提供了一种自动化的机制来访问和存储数据库中的数据. ...
- 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 ...
- lua模块demo(redis,http,mysql,cjson,本地缓存)
1. lua模块demo(redis,http,mysql,cjson,本地缓存) 1.1. 配置 在nginx.conf中设置lua_shared_dict my_cache 128m; 开启ngi ...
- 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 ...
- 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 ...
- Mvc5+Entity Framework6 之二----在MVC中用Entity Framework实现基本的CRUD
目标:创建控制器和视图的代码,实现CRUD(创建,读取,更新,删除)功能 创建一个详细信息页 控制器为Students的Index页生成的代码排除Enrollments属性在外,因为该属性中关联着一个 ...
- Entity Framework Core系列之什么是Entity Framework Core
前言 Entity Framework Core (EF Core)是微软推荐的基于.NET Core framework的应用程序数据访问技术.它是轻量级,可扩展并且支持跨平台开发.EF Core是 ...
- 如何修改Entity Framework Db Frist模式下的Entity继承关系?
1.准备工作 Db Frist创建实体数据模型(创建edmx并不是重点,各位随意即可),此处取名ZeroCodeDB,所得文件如图所示:其中红框中的文件(ZeroCodeDB.tt)是各实体的生成的关 ...
随机推荐
- Delegate,Action,Func,匿名方法,匿名委托,事件 (转载)
Delegate,Action,Func,匿名方法,匿名委托,事件 (转载) 一.委托Delegate 一般的方法(Method)中,我们的参数总是string,int,DateTime...这些基本 ...
- samtools flagstat
samtools flagstat命令简介: 统计输入文件的相关数据并将这些数据输出至屏幕显示.每一项统计数据都由两部分组成,分别是QC pass和QC failed,表示通过QC的reads数据量和 ...
- vue.js实现购物车功能
购物车是电商必备的功能,可以让用户一次性购买多个商品,常见的购物车实现方式有如下几种: 1. 用户更新购物车里的商品后,页面自动刷新. 2. 使用局部刷新功能,服务器端返回整个购物车的页面html 3 ...
- yii2自定义json格式success,error跳转
/** * ---------------------------------------------- * 操作成功跳转的快捷方法 * @access protected * @param stri ...
- jQuery 常用效果
hide和show 同样有 fadeInhe fadeOut 的功能 $(document).ready(function(){ $("#hide").click(function ...
- SQL语句or查询,union all查询,分页查询,分组,AND查询
一.OR查询 1.在AND多个筛选条件和一个or条件时,如果没有括号包裹,or会就近原则包裹之后的所有and条件,也就是同级的多个and条件只能对,or条件的一边起作用 2.如果or条件两边的筛选条件 ...
- 安卓修改开机logo和开机动画的方法
第一种和第二种方法亲测可用,安卓版本是4.2和安卓5.1均可.第二种方法待验证 以下三种方法 Android 开机其实总共会出现3个画面: 1.第一个就是 linux 系统启动,出现Linux小企鹅画 ...
- Kotlin, Android的Swift
Kotlin, Android的Swift 苹果已经用Swift代替Objective-C,一种古老的语言,来进行iOS的开发了.明显Android开发也有这个趋势. 虽然现在已经可以选择Scala或 ...
- Different timers in .net
Multi-threads timers: System.Threading.Timer and System.Timers.Timer (.net framework): App will hand ...
- 20169207《linux内核原理与分析》第二周作业
第一部分:学习MOOC网Linux内核分析的课程. 首先对冯诺依曼体系结构和存储程序计算机工作模型进行了了解,查阅资料,对冯诺依曼体系的特点与课堂上的相结合,真实明白了模型的特点. 在汇编C语言程序时 ...