從 EF Core 1.0 RC2 升級至 RTMUpgrading from EF Core 1.0 RC2 to RTM

本文章提供移動 1.0.0 RC2 封裝建置的應用程式的指引 RTM。This article provides guidance for moving an application built with the RC2 packages to 1.0.0 RTM.

封裝版本Package Versions

您通常會安裝到應用程式的最上層封裝名稱 RC2 及 RTM 之間並沒有變更。The names of the top level packages that you would typically install into an application did not change between RC2 and RTM.

您需要在 RTM 版本升級已安裝的套件:You need to upgrade the installed packages to the RTM versions:

  • 執行階段封裝 (例如Microsoft.EntityFrameworkCore.SqlServer) 從變更1.0.0-rc2-final1.0.0Runtime packages (e.g. Microsoft.EntityFrameworkCore.SqlServer) changed from 1.0.0-rc2-final to 1.0.0.

  • Microsoft.EntityFrameworkCore.Tools封裝變更從1.0.0-preview1-final1.0.0-preview2-finalThe Microsoft.EntityFrameworkCore.Tools package changed from 1.0.0-preview1-final to 1.0.0-preview2-final. 請注意,工具仍然發行前版本。Note that tooling is still pre-release.

現有的移轉可能需要加入 maxLengthExisting migrations may need maxLength added

Rc2,移轉的資料行定義看起來像table.Column<string>(nullable: true),我們會儲存在移轉後的程式碼中的某些中繼資料中查閱資料行的長度。In RC2, the column definition in a migration looked like table.Column<string>(nullable: true) and the length of the column was looked up in some metadata we store in the code behind the migration. 在 RTM,長度現在會包含在程式碼 scaffold table.Column<string>(maxLength: 450, nullable: true)In RTM, the length is now included in the scaffolded code table.Column<string>(maxLength: 450, nullable: true).

不會有任何現有的移轉作業的已使用 RTM 之前 scaffoldmaxLength指定引數。Any existing migrations that were scaffolded prior to using RTM will not have the maxLength argument specified. 這表示將使用之資料庫所支援的最大長度 (nvarchar(max) SQL Server 上)。This means the maximum length supported by the database will be used (nvarchar(max) on SQL Server). 這可能是正常的某些資料行,但屬於索引鍵,外部索引鍵,資料行或索引需要更新成包含最大長度。This may be fine for some columns, but columns that are part of a key, foreign key, or index need to be updated to include a maximum length. 依照慣例,450 是最大長度用於索引鍵,外部索引鍵和索引資料行。By convention, 450 is the maximum length used for keys, foreign keys, and indexed columns. 如果您在模型中明確設定的長度,然後您應該改用該長度。If you have explicitly configured a length in the model, then you should use that length instead.

ASP.NET IdentityASP.NET Identity

這項變更會影響使用 ASP.NET Identity,並且從預先建立的專案-RTM 專案範本。This change impacts projects that use ASP.NET Identity and were created from a pre-RTM project template. 專案範本包含用來建立資料庫的移轉。The project template includes a migration used to create the database. 此移轉必須編輯成指定的最大長度256下列資料行。This migration must be edited to specify a maximum length of 256 for the following columns.

  • AspNetRolesAspNetRoles

    • 名稱Name

    • NormalizedNameNormalizedName

  • AspNetUsersAspNetUsers

    • EmailEmail

    • NormalizedEmailNormalizedEmail

    • NormalizedUserNameNormalizedUserName

    • 使用者名稱UserName

初始移轉套用至資料庫時,無法進行這項變更會導致下列的例外狀況。Failure to make this change will result in the following exception when the initial migration is applied to a database.

System.Data.SqlClient.SqlException (0x80131904): Column 'NormalizedName' in table 'AspNetRoles' is of a type that is invalid for use as a key column in an index.

.NET core: 在 project.json 中移除 「 匯入 」.NET Core: Remove "imports" in project.json

如果您已針對.NET Core rc2,您需要新增imports加入 project.json 暫時的解決方法的其中一些不支援.NET 標準的 EF 核心相依性。If you were targeting .NET Core with RC2, you needed to add imports to project.json as a temporary workaround for some of EF Core's dependencies not supporting .NET Standard. 這些是可以立即移除。These can now be removed.

{
  "frameworks": {
    "netcoreapp1.0": {
      "imports": ["dnxcore50", "portable-net451+win8"]
    }
  }
}

注意

自 1.0 版 RTM, .NET Core SDK已不再支援project.json或開發使用 Visual Studio 2015 的.NET Core 應用程式。As of version 1.0 RTM, the .NET Core SDK no longer supports project.json or developing .NET Core applications using Visual Studio 2015. 建議您從 project.json 移轉至 csprojWe recommend you migrate from project.json to csproj. 如果您使用 Visual Studio,我們建議您升級到Visual Studio 2017If you are using Visual Studio, we recommend you upgrade to Visual Studio 2017.

UWP: 新增繫結重新導向UWP: Add binding redirects

嘗試執行 EF 命令在通用 Windows 平台 (UWP) 專案會導致下列錯誤:Attempting to run EF commands on Universal Windows Platform (UWP) projects results in the following error:

System.IO.FileLoadException: Could not load file or assembly 'System.IO.FileSystem.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

您需要手動新增繫結重新導向至 UWP 專案。You need to manually add binding redirects to the UWP project. 建立名為App.config專案中的根資料夾和重新導向加入至正確的組件版本。Create a file named App.config in the project root folder and add redirects to the correct assembly versions.

<configuration>
 <runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
       <assemblyIdentity name="System.IO.FileSystem.Primitives"
                         publicKeyToken="b03f5f7f11d50a3a"
                         culture="neutral" />
       <bindingRedirect oldVersion="4.0.0.0"
                        newVersion="4.0.1.0"/>
     </dependentAssembly>
     <dependentAssembly>
       <assemblyIdentity name="System.Threading.Overlapped"
                         publicKeyToken="b03f5f7f11d50a3a"
                         culture="neutral" />
       <bindingRedirect oldVersion="4.0.0.0"
                        newVersion="4.0.1.0"/>
     </dependentAssembly>
   </assemblyBinding>
 </runtime>
</configuration>