Entity Framework升级
第三篇是Entity Framework升級(jí)
修改project.json
把原來 EntityFramework 的包 換成 Microsoft.EntityFrameworkCore
版本從 7.0.0-rc1-final?改為 1.0.0-rc2-final
對(duì)照表如下:
| 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 配置節(jié)中加入
| 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的相關(guān)cli命令,由原來的 dnx ef 改為 dotnet ef,具體可以通過 dotnet ef --help 來查看
修改代碼中的命名空間
把原來的 Microsoft.Data.Entity 改為 Microsoft.EntityFrameworkCore
這里可以批量查找替換掉
修改Startup.cs
RC2中已經(jīng)移除了AddEntityFramework()、AddInMemoryDatabase()、AddSqlServer(),所以我們也要在代碼中相應(yīng)的移除掉它們,以我自己的項(xiàng)目中為例子
原來為:
| 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(); ???????? } |
現(xiàn)在則改為:
| 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(); ???????? } |
相關(guān)文章:
ASP.NET Core 1.0 入門——了解一個(gè)空項(xiàng)目
ASP.NET Core 1.0 部署 HTTPS (.NET Framework 4.5.1)
.NET Core 1.0、ASP.NET Core 1.0和EF Core 1.0簡(jiǎn)介
云服務(wù)器下ASP.NET Core 1.0環(huán)境搭建(包含mono與coreclr)
使用VS Code開發(fā)ASP.NET Core 應(yīng)用程序
dotnet run是如何啟動(dòng)asp.net core站點(diǎn)的
ASP.NET Core提供模塊化Middleware組件
“dotnet restore"和"dotnet run"都做了些什么?
探秘 dotnet run 如何運(yùn)行 .NET Core 應(yīng)用程序
.NET Portability Analyzer 已開源
ASP.NET Core的配置(1):讀取配置信息
ASP.NET Core的配置(2):配置模型詳解
.NET Core 1.0 RC2 歷險(xiǎn)之旅
使用VS Code開發(fā) 調(diào)試.NET Core 應(yīng)用程序
讓我們Core在一起:ASP.NET Core & .NET Core
.NET Core VS Code 環(huán)境配置
官方博客明確了 .NET Core RC2/RTM 時(shí)間表
.NET Core全新的配置管理[共9篇]
利用記事本創(chuàng)建一個(gè)ASP.NET Core RC2 MVC應(yīng)用
微軟.NET 正式劈腿成功,橫跨所有平臺(tái)
.NET Core 1.0 CentOS7 嘗試
解讀發(fā)布:.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社區(qū)新聞,深度好文,微信中搜索dotNET跨平臺(tái)或掃描二維碼關(guān)注
贊賞
人贊賞
總結(jié)
以上是生活随笔為你收集整理的Entity Framework升级的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TFS2015的CI集成
- 下一篇: IIS负载均衡-Application