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)是各实体的生成的关 ...
随机推荐
- VB.NET and C# 差异
VB.NET Program Structure C# Imports System Namespace Hello Class HelloWorld Overloads Share ...
- Java:斐波那契数列
斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10 ...
- spring boot中注入jpa时报could not autowire.No beans of 'PersonRepository' type found
解决方法,在repository加一个注解.如下图所示: @Component
- vue 开发系列(八) 动态表单开发
概要 动态表单指的是我们的表单不是通过vue 组件一个个编写的,我们的表单是根据后端生成的vue模板,在前端通过vue构建出来的.主要的思路是,在后端生成vue的模板,前端通过ajax的方式加载后端的 ...
- 证明LDU分解的唯一性
首先上(下)三角矩阵乘以上(下)三角矩阵结果还是上(下)三角矩阵, 另外我们考虑相乘后的对角元素可发现,对角原始是原来2矩阵对应对角元素的乘积. 另外对角线都是1的上(下)三角矩阵必定可以只是用行运算 ...
- day23(事务管理)
事务管理 事务管理两种方式: 向下传递,ThreadLocal 向下传递的方式(依赖) 缺点:不利于测试 Service层 获取连接conn(Connection) 转账(conn) 收账(conn) ...
- pyppeteer使用笔记
pyppeteer -- python版本的puppeteer,一个强大的chronium headless浏览器API 最近搞天猫用了一波儿,记录一下. 先上文档: https://miyakogi ...
- 【repost】DOM CRUD
//DOM 的 CRUD // c 创建create // 1.直接往body中动态的添加标签(可以是任意类型)document.write('helloWorld');document.write( ...
- 【python-crypto】导入crypto包失败的情况,怎么处理
[python-crypto]导入crypto包失败的情况,怎么处理 是因为你自己安装的python的版本太高,所以自己降版本吧,捣鼓了一下午 pip install crypto pip insta ...
- java基础-day9
第09天 java集合 今日内容介绍 u 对象数组 u 集合类之ArrayList u 学生管理系统案例 第1章 对象数组 1.1 对象数组概述 A:基本类型的数组:存储的元素为基本类型 ...