Entity Framework 6Entity Framework 6

Entity Framework 6 (EF6) 是通過試驗及測試的 .NET 物件關聯式對應程式 (O/RM),歷經多年的功能開發和穩固。Entity Framework 6 (EF6) is a tried and tested object-relational mapper (O/RM) for .NET with many years of feature development and stabilization.

作為 O/RM,EF6 可減少關聯式與物件導向環境之間的阻抗不相符情況,讓開發人員能夠撰寫使用強型別 .NET 物件 (其代表應用程式網域) 與關聯式資料庫中儲存的資料進行互動的應用程式,因此通常不需要撰寫大部分的資料存取「配管」程式碼。As an O/RM, EF6 reduces the impedance mismatch between the relational and object-oriented worlds, enabling developers to write applications that interact with data stored in relational databases using strongly-typed .NET objects that represent the application's domain, and eliminating the need for a large portion of the data access "plumbing" code that they usually need to write.

EF6 會實作許多常用的 O/RM 功能:EF6 implements many popular O/RM features:

  • 對應 POCO 實體類別,其不相依於任何 EF 類型Mapping of POCO entity classes which do not depend on any EF types
  • 自動變更追蹤Automatic change tracking
  • 識別解析和工作單位Identity resolution and Unit of Work
  • 積極式、消極式和明確式載入Eager, lazy and explicit loading
  • 使用 LINQ (Language INtegrated Query) 的強型別查詢轉譯Translation of strongly-typed queries using LINQ (Language INtegrated Query)
  • 豐富的對應功能,包括下列項目的支援:Rich mapping capabilities, including support for:
    • 一對一、一對多及多對多關聯性One-to-one, one-to-many and many-to-many relationships
    • 繼承 (每個階層的資料表、每個類型的資料表,以及每個實體類別的資料表)Inheritance (table per hierarchy, table per type and table per concrete class)
    • 複雜類型Complex types
    • 預存程序Stored procedures
  • 用來建立實體模型的視覺化設計工具。A visual designer to create entity models.
  • 藉由撰寫程式碼來建立實體模型的「Code First」體驗。A "Code First" experience to create entity models by writing code.
  • 您可以從現有資料庫產生模型,然後手動編輯,也可以從頭開始建立模型,然後用來產生新的資料庫。Models can either be generated from existing databases and then hand-edited, or they can be created from scratch and then used to generate new databases.
  • 與 .NET Framework 應用程式模型 (包括 ASP.NET) 的整合,或透過資料繫結與 WPF 和 WinForms 的整合。Integration with .NET Framework application models, including ASP.NET, and through databinding, with WPF and WinForms.
  • 依據 ADO.NET 和許多提供者的資料庫連線,可用來連線至 SQL Server、Oracle、MySQL、SQLite、PostgreSQL、DB2 等等。Database connectivity based on ADO.NET and numerous providers available to connect to SQL Server, Oracle, MySQL, SQLite, PostgreSQL, DB2, etc.

我應該使用 EF6 還是 EF Core?Should I use EF6 or EF Core?

EF Core 是 Entity Framework 的新式輕量型可延伸版本,具有非常類似於 EF6 的功能和優點。EF Core is a more modern, lightweight and extensible version of Entity Framework that has very similar capabilities and benefits to EF6. EF Core 是完全重新撰寫的版本,包含許多 EF6 並未提供的新功能,但它仍然缺少一些 EF6 最先進的對應功能。EF Core is a complete rewrite and contains many new features not available in EF6, although it also still lacks some of the most advanced mapping capabilities of EF6. 如果功能集符合您的需求,請考慮在新的應用程式中使用 EF Core。Consider using EF Core in new applications if the feature set matches your requirements. 比較 EF Core 與 EF6可更詳細地檢查這項選擇。Compare EF Core & EF6 examines this choice in greater detail.

開始使用Get Started

將 EntityFramework NuGet 套件新增至您的專案,或安裝 Entity Framework Tools for Visual StudioAdd the EntityFramework NuGet package to your project or install the Entity Framework Tools for Visual Studio. 接著觀看影片、閱讀教學課程和進階文件,以協助您充分利用 EF6。Then watch videos, read tutorials, and advanced documentation to help you make the most of EF6.

過去的 Entity Framework 版本Past Entity Framework Versions

這是適用於最新版 Entity Framework 6 的文件,但其中的大部分內容也適用於過去的版本。This is the documentation for the latest version of Entity Framework 6, although much of it also applies to past releases. 如需 EF 版本和它們所引進功能的完整清單,請參閱新功能過去的版本Check out What's New and Past Releases for a complete list of EF releases and the features they introduced.