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)是各实体的生成的关 ...
随机推荐
- 实现WireCard支付
实现WireCard支付,暂未完成 WireCardController.cs using System; using System.Collections.Generic; using System ...
- linux系统,在centos7环境下安装jdk步骤
记录一下安装jdk1.8版本的出错过程: 按照这个博客内容安装的,以及修改文件权限博客 [Linux]CentOS7下安装JDK详细过程 [Linux]目录文件权限的查看和修改[转] 1.安装的jdk ...
- mysql里几个超时配置参数wait_timeout,net_read_timeout等
以下这些配置项单位都是秒,在mysql命令行中可以使用show global variables like '变量名';可查询配置值. connect_timeout:连接响应超时时间.服务器端在这个 ...
- 2018.10.25 洛谷P4187 [USACO18JAN]Stamp Painting(计数dp)
传送门 其实本来想做组合数学的2333. 谁知道是道dpdpdp. 唉只能顺手做了 还是用真难则反的思想. 这题我们倒着考虑,只需要求出不合法方案数就行了. 这个显然是随便dpdpdp的. f[i]f ...
- MySQL按日、周、月统计数据
知识关键词:DATE_FORMAT ps:如果时间字段为时间戳则,DATE_FORMAT(from_unixtime(create_time),'%Y-%u') select DATE_FORMAT( ...
- caffe 笔记
caffe模块: blob:caffe中数据的封装,用于layer上流动 layer:输入层.输出层.神经网络层的抽象 net:神经网络结构,将layer层叠关联起来 solver:定义神经网络训练和 ...
- 本地导入/导出远程oracle数据库
1.导出数据库 exp 用户名/密码@远程服务器IP:数据端口号/实例名 file=存储dmp文件的路径 full=y; 2.导入数据库 imp 用户名/密码@远程服务器IP:数据库端口号/实例名 f ...
- netfilter框架和iptables
转载自:http://blog.chinaunix.net/uid-23069658-id-3160506.html http://blog.chinaunix.net/uid-23069658-id ...
- p1 批梯度下降算法
(蓝色字体:批注:绿色背景:需要注意的地方:橙色背景是问题) 一,机器学习分类 二,梯度下降算法:2.1模型 2.2代价函数 2.3 梯度下降算法 一,机器学习分类 无监督学习和监督学习 无监 ...
- vue中$route 和$router的区别
在vue中会出现一种情况 const url=this.$route.query.returnURL; this.$router.push(url); $router和$route的区别傻傻的分 ...