SQL Server EF Core 資料庫提供者的記憶體最佳化資料表支援Memory-Optimized Tables support in SQL Server EF Core Database Provider


在 EF Core 1.1 已引入此功能。This feature was introduced in EF Core 1.1.

記憶體最佳化資料表是整個資料表在記憶體中的所在位置的 SQL Server 的功能。Memory-Optimized Tables are a feature of SQL Server where the entire table resides in memory. 第二份資料表的資料會保留在磁碟上,但只做為持久性用途。A second copy of the table data is maintained on disk, but only for durability purposes. 從磁碟復原資料庫期間只讀取記憶體最佳化資料表中的資料。Data in memory-optimized tables is only read from disk during database recovery. 例如,在伺服器重新啟動。For example, after a server restart.

設定記憶體最佳化資料表Configuring a memory-optimized table

您可以將實體所對應的資料表指定為記憶體最佳化。You can specify that the table an entity is mapped to is memory-optimized. 當使用來建立並維護資料庫的 EF Core 根據您的模型 (不論是透過移轉或Database.EnsureCreated()),記憶體最佳化資料表將會建立針對這些實體。When using EF Core to create and maintain a database based on your model (either with migrations or Database.EnsureCreated()), a memory-optimized table will be created for these entities.

protected override void OnModelCreating(ModelBuilder modelBuilder)