博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
EntityFramework 7 Migrations 迁移命令
阅读量:6857 次
发布时间:2019-06-26

本文共 2165 字,大约阅读时间需要 7 分钟。

示例代码:

using Microsoft.Data.Entity;using System.Collections.Generic;namespace ClassLibrary1{    public class BloggingContext : DbContext    {        public DbSet
Blogs { get; set; } public DbSet
Posts { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(@"Server=DESKTOP-2P9GHDD\SA;Database=BloggingContextDb;User ID=sa;Password=123456;"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { // Make Blog.Url required modelBuilder.Entity
() .Property(b => b.Url) .IsRequired(); } } public class Blog { public int BlogId { get; set; } public string Url { get; set; } public List
Posts { get; set; } } public class Post { public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public int BlogId { get; set; } public Blog Blog { get; set; } }}

project.json 配置代码:

{  "version": "1.0.0-*",  "description": "ClassLibrary1 Class Library",  "authors": [ "xishuai" ],  "tags": [ "" ],  "projectUrl": "",  "licenseUrl": "",  "frameworks": {    "dnx451": { }  },  "dependencies": {    "EntityFramework.Core": "7.0.0-rc1-final",    "EntityFramework.Commands": "7.0.0-rc1-final",    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"  },  "commands": {    "ef": "EntityFramework.Commands"  }}

命令行转到程序目录,运行 dnx ef,如果出现“找不到命令”提示,先运行 dnvm upgrade

dnvm upgradednu restorecd src\MyProjectdnx efdnx ef migrations add MyMigrationdnx ef database update

dnx ef 命令:

dnx ef migrations add MyMigration 命令:

dnx ef database update 命令:

dnx ef migrations --help 帮助:

  • database
    • update–Updates the database to a specified migration
  • dbcontext
    • list–List your DbContext types
    • scaffold–Scaffolds a DbContext and entity type classes for a specified database
  • migrations
    • add–Add a new migration
    • list–List the migrations
    • remove–Remove the last migration
    • script–Generate a SQL script from migrations

参考资料:

转载地址:http://whjyl.baihongyu.com/

你可能感兴趣的文章
Hibernate 分页时 Long 无法转化成Integer类型 异常
查看>>
鸡和蛋的OO设计
查看>>
XML中SystemID和PublicID的区别
查看>>
windows 下查看端口占用情况
查看>>
Thread源码分析
查看>>
左值、右值与右值引用
查看>>
狮入羊口
查看>>
C++容器类的简介
查看>>
RHEL6 某业务用户ulimit -a命令找不到
查看>>
oracle定时任务
查看>>
Chrome 错误代码:ERR_UNSAFE_PORT
查看>>
spring mvc4的日期/数字格式化、枚举转换
查看>>
阿里云服务器mysql修改编码问题
查看>>
算法生成N芒星
查看>>
StringTokenizer类的使用
查看>>
下载安装tomcat6.0
查看>>
基于正则的INI读写工具类,支持加密解密
查看>>
java中的native关键字
查看>>
Live555类结构
查看>>
java:快速文件分割及合并
查看>>