Entity Framework升级

来源:互联网 发布:c语言数组合并 编辑:程序博客网 时间:2024/06/15 23:56

第三篇是Entity Framework升级

修改project.json

把原来 EntityFramework 的包 换成 Microsoft.EntityFrameworkCore

版本从 7.0.0-rc1-final 改为 1.0.0-rc2-final

对照表如下:

RC1 Package RC2 Equivalent EntityFramework.MicrosoftSqlServer 7.0.0-rc1-final Microsoft.EntityFrameworkCore.SqlServer 1.0.0-rc2-final EntityFramework.SQLite 7.0.0-rc1-final Microsoft.EntityFrameworkCore.SQLite 1.0.0-rc2-final EntityFramework7.Npgsql 3.1.0-rc1-3 NpgSql.EntityFrameworkCore.Postgres <to be advised> EntityFramework.SqlServerCompact35 7.0.0-rc1-final EntityFrameworkCore.SqlServerCompact35 1.0.0-rc2-final EntityFramework.SqlServerCompact40 7.0.0-rc1-final EntityFrameworkCore.SqlServerCompact40 1.0.0-rc2-final EntityFramework.InMemory 7.0.0-rc1-final Microsoft.EntityFrameworkCore.InMemory 1.0.0-rc2-final EntityFramework.IBMDataServer 7.0.0-beta1 Not yet available for RC2 EntityFramework.Commands 7.0.0-rc1-final Microsoft.EntityFrameworkCore.Tools 1.0.0-preview1-final EntityFramework.MicrosoftSqlServer.Design 7.0.0-rc1-final Microsoft.EntityFrameworkCore.SqlServer.Design 1.0.0-rc2-final

增加EF cli工具

在 project.json 的 tools 配置节中加入

1
2
3
4
5
6
7
"Microsoft.EntityFrameworkCore.Tools" : {
     "version" "1.0.0-preview1-final" ,
     "imports" : [
         "portable-net45+win8+dnxcore50" ,
         "portable-net45+win8"
     ]
}

EF的相关cli命令,由原来的 dnx ef 改为 dotnet ef,具体可以通过 dotnet ef --help 来查看

修改代码中的命名空间

把原来的 Microsoft.Data.Entity 改为 Microsoft.EntityFrameworkCore

这里可以批量查找替换掉

修改Startup.cs

RC2中已经移除了AddEntityFramework()、AddInMemoryDatabase()、AddSqlServer(),所以我们也要在代码中相应的移除掉它们,以我自己的项目中为例子

原来为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
         public void ConfigureServices(IServiceCollection services)
         {
#if DEBUG
             services.AddEntityFramework()
                 .AddInMemoryDatabase()
                 .AddDbContext<EFContext>(option => {
                     option.UseInMemoryDatabase();
                 });
#else
             services.AddEntityFramework()
                 .AddSqlServer()
                 .AddDbContext<EFContext>(option => {
                     option.UseSqlServer(Configuration[ "Data:DefaultConnection:ConnectionString" ]);
                 });
#endif
             services.AddApplicationInsightsTelemetry(Configuration);
             // Add framework services.
             services.AddMvc();
         }

现在则改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
         public void ConfigureServices(IServiceCollection services)
         {
#if DEBUG
             services.AddDbContext<EFContext>(option =>
             {
                 option.UseInMemoryDatabase();
             });
#else
             services.AddDbContext<EFContext>(option =>
             {
                 option.UseSqlServer(Configuration[ "Data:DefaultConnection:ConnectionString" ]);
             });
#endif
             // Add framework services.
             services.AddMvc();
         }


相关文章:

  • ASP.NET Core 1.0 入门——了解一个空项目

  • ASP.NET Core 1.0 部署 HTTPS (.NET Framework 4.5.1)

  • .NET Core 1.0、ASP.NET Core 1.0和EF Core 1.0简介

  • 云服务器下ASP.NET Core 1.0环境搭建(包含mono与coreclr)

  • 使用VS Code开发ASP.NET Core 应用程序

  • dotnet run是如何启动asp.net core站点的

  • ASP.NET Core提供模块化Middleware组件

  • “dotnet restore"和"dotnet run"都做了些什么?

  • 探秘 dotnet run 如何运行 .NET Core 应用程序

  • .NET Portability Analyzer 已开源

  • ASP.NET Core的配置(1):读取配置信息

  • ASP.NET Core的配置(2):配置模型详解

  • .NET Core 1.0 RC2 历险之旅

  • 使用VS Code开发 调试.NET Core 应用程序

  • 让我们Core在一起:ASP.NET Core & .NET Core

  • .NET Core VS Code 环境配置

  • 官方博客明确了 .NET Core RC2/RTM 时间表

  • .NET Core全新的配置管理[共9篇]

  • 利用记事本创建一个ASP.NET Core RC2 MVC应用

  • 微软.NET 正式劈腿成功,横跨所有平台

  • .NET Core 1.0 CentOS7 尝试

  • 解读发布:.NET Core RC2 and .NET Core SDK Preview 1

  • [.NET Core].NET Core R2安装及示例教程


原文地址:http://blog.lishewen.com/post/upgrade-thenet-core-rc2-(3)-those-things-the-entity-framework-to-upgrade


.NET社区新闻,深度好文,微信中搜索dotNET跨平台或扫描二维码关注

原创粉丝点击