從 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 (for example, 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 身分識別ASP.NET Identity

這項變更會影響使用 ASP.NET 身分識別,並從預先建立的專案-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 Core 相依性。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>