Code first, DB update
来源:互联网 发布:淘宝买家两钻有什么用 编辑:程序博客网 时间:2024/06/05 08:34
1, change code in model, add/delete new field to table, update db.
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data.Entity;using System.ComponentModel.DataAnnotations;namespace MvcMovie.Models{ public class Movie { public int ID { get; set; } [Required] public string Title { get; set; } [DataType(DataType.Date)] public DateTime ReleaseDate { get; set; } [Required] [StringLength(5)] public string Genre { get; set; } [Range(1,100)] public decimal Price { get; set; } [Required] public int rate { get; set; } public string test { get; set; } // add new field or delete this field } public class MovieDBContext : DbContext { public DbSet<Movie> Movies { get; set; } }}
2, tool -> library manager -> package manager console.
run command: Enable-Migrations -ContextTypeName MvcMovie.Models.MovieDBContext (your model namespace.DBcontextClass)
- this command will create folder Migrations and configuration.cs in it
- only need run once (if you don't have folder Migrations or the folder Migrations has been deleted)
- if you have folder Migrations and configruation.cs in it. go to next step.
3. in package manager console.
run command: add-migration AddDataAnnotationsMig
- this command will detect the change you made and generate code to change the db.
- example: Migrations/201302041554137_AddDataAnnotationsMig3.cs
4. run command:
run command: update-database
- Code first, DB update
- 简介: 逆向操作DB到Code First Classes
- Model First, Database First or Code First–Update to Data Points Column
- Code First
- code first
- code first
- First Code
- MVC5 DB FIRST
- PLSQL Recursion DB Update
- [DB] MySQL UPDATE查询
- First Update Blog
- Code First Entity Framework基本与最佳添加(add/create),删除(delete/remove),修改(update/modify)操作
- Code First DataAnnotations
- Code First一些问题
- Node(2) First Code
- 【Code First】 Data Seed
- ef-->code first-->Migrations
- ef code first例子
- 高斯消元法(解齐次方程组)
- sql server 2005/2008修改排序规则
- 在win7已安装VS2010情况下建Visual Studio 2005带有NetAdvantage2005控件的开发环境
- 不同的几何图形的渲染方式
- js 状态栏逐字显示文字
- Code first, DB update
- ABAP CHECKBOX 选中事件
- DataGuard 之物理STANDBY 的监控与管理
- cocos2d安装
- XMLHttpRequest对象初始化
- java之Stirng和Date转换
- 强矩阵中的人员管理
- Linux NFS 服务配置及AIX NFS 客户端挂载实施步骤
- java.io.FileNotFoundException: /exapp/hadoop/name/current/VERSION (Permission denied)