Entity Framework升级
第三篇是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跨平臺或掃描二維碼關注
贊賞
人贊賞
總結
以上是生活随笔為你收集整理的Entity Framework升级的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TFS2015的CI集成
- 下一篇: IIS负载均衡-Application