升級EF6的步驟與程式修改 (Updating Applications to use EF6)

摘要:升級EF6的步驟與程式修改 (Updating Applications to use EF6)



 

 

 

原文出處:http://entityframework.codeplex.com/wikipage?title=Updating%20Applications%20to%20use%20EF6

 

== 步  驟 :==================================================

第一,透過Visual Studio的 NuGet,搜尋 Entity字眼,就能找到 Entity Framework 6

新版 EF6 會加入這兩個
EntityFramework.dll – All the common runtime code used by EF
EntityFramework.SqlServer.dll – The Microsoft SQL Server provider for EF
 

 

第二,刪除舊有的 System.Data.Entity.dll版本(我個人建議:使用「空網站」來作,就比較沒這困擾)

 

第三,http://msdn.microsoft.com/en-us/data/dn469466

      如果您有透過工具產生EDMX的話 這篇文章的第三步驟要看一下:

Swap any EF Designer (EDMX) models to use EF 6.x code generation

 

If you have any models created with the EF Designer, you will need to update the code generation templates to generate EF6 compatible code.
Note: There are currently only EF 6.x DbContext Generator templates available for Visual Studio 2012 and 2013.

  1. Delete existing code-generation templates. These files will typically be named <edmx_file_name>.tt and <edmx_file_name>.Context.ttand be nested under your edmx file in Solution Explorer. You can select the templates in Solution Explorer and press the Del key to delete them.
    Note: In Web Site projects the templates will not be nested under your edmx file, but listed alongside it in Solution Explorer.
    Note: In VB.NET projects you will need to enable 'Show All Files' to be able to see the nested template files.
  2. Add the appropriate EF 6.x code generation template. Open your model in the EF Designer, right-click on the design surface and select Add Code Generation Item...
    • If you are using the DbContext API (recommended) then EF 6.x DbContext Generator will be available under the Data tab.
      Note: If you are using Visual Studio 2012, you will need to install the EF 6 Tools to have this template. See Get Entity Framework for details.
    • If you are using the ObjectContext API then you will need to select the Online tab and search for EF 6.x EntityObject Generator.
  3. If you applied any customizations to the code generation templates you will need to re-apply them to the updated templates

 

第四,命名空間(NameSpace)又有異動

以前名為 System.Data.*的命名空間,都要改成 System.Data.Entity.Core.*

但有些「例外」,請看:

These types are in the Core namespaces because they are not used directly for most DbContext-based applications. Some types that were part of System.Data.Entity.dll are still used commonly and directly for DbContext-based applications and so have not been moved into the Core namespaces. These are:

  • System.Data.EntityState => System.Data.Entity.EntityState

  • System.Data.Objects.DataClasses.EdmFunctionAttribute =>System.Data.Entity.DbFunctionAttribute(Note that the class has been renamed; a class with the old name still exists and works, but it now marked as obsolete.)

  • System.Data.Objects.EntityFunctions => System.Data.Entity.DbFunctions (Note that the class has been renamed; a class with the old name still exists and works, but it now marked as obsolete.)

  • Spatial classes (e.g. DbGeography, DbGeometry) have moved from System.Data.Spatial => System.Data.Entity.Spatial

 

 

改版、變化、幹剿.......習慣就好,這就是IT人生  :-)

 

以前在 EF 4.0撰寫的程式,如果不能使用(尤其是ObjectQuery),可以參閱以下文章

Attempt to use ObjectQuery does not work
 
 
Cannot implicitly convert type 'System.Data.Entity.Core.Objects.ObjectResult<string>' to 'System.Data.Objects.ObjectResult<string>'
 
 
還原成 ObjectContext
在 VS2012 中建立的新模型會產生使用 DbContext 的程式碼,不過您可以還原成 ObjectContext。
http://msdn.microsoft.com/zh-tw/data/jj556581  (點選下圖可連結到原文)
 
 
Entity Framework 5 的效能考量(這篇文章有一些範例與程式碼)

 

 

 

 

我將思想傳授他人, 他人之所得,亦無損於我之所有;

猶如一人以我的燭火點燭,光亮與他同在,我卻不因此身處黑暗。----Thomas Jefferson

線上課程教學,遠距教學 (Web Form 約 51hr)  https://dotblogs.com.tw/mis2000lab/2016/02/01/aspnet_online_learning_distance_education_VS2015

線上課程教學,遠距教學 (ASP.NET MVC 約 135hr)  https://dotblogs.com.tw/mis2000lab/2018/08/14/ASPnet_MVC_Online_Learning_MIS2000Lab

 

寫信給我,不要私訊 --  mis2000lab (at) yahoo.com.tw  或  school (at) mis2000lab.net

 (1) 第一天 ASP.NET MVC5 完整影片(5.5小時 / .NET 4.x版)免費試聽。影片 https://youtu.be/9spaHik87-A 

 (2) 第一天 ASP.NET Core MVC 完整影片(3小時 / .NET Core 6.0~8.0)免費試聽。影片 https://youtu.be/TSmwpT-Bx4I 

[學員感言] mis2000lab課程評價 - ASP.NET MVC , WebForm  。 https://mis2000lab.medium.com/%E5%AD%B8%E5%93%A1%E6%84%9F%E8%A8%80-mis2000lab%E8%AA%B2%E7%A8%8B%E8%A9%95%E5%83%B9-asp-net-mvc-webform-77903ce9680b  


ASP.NET遠距教學、線上課程(Web Form + MVC)。 第一天課程, "完整" 試聽。 

.........   facebook社團   https://www.facebook.com/mis2000lab   ......................

.........  YouTube (ASP.NET) 線上教學影片  https://www.youtube.com/channel/UC6IPPf6tvsNG8zX3u1LddvA/

 

Blog文章 "附的範例" 無法下載,請看 https://dotblogs.com.tw/mis2000lab/2016/03/14/2008_2015_mis2000lab_sample_download

請看我們的「售後服務」範圍(嚴格認定)。

...................................................................................................................................................... 

ASP.NET MVC  => .NET Core MVC 線上教學  ...... 第一天課程 完整內容 "免費"讓您評估 / 試聽

[遠距教學、教學影片] ASP.NET (Web Form) 課程 上線了!MIS2000Lab.主講   事先錄好的影片,並非上課側錄!   觀看時,有如「一對一」面對面講課