内存优化表支持 SQL Server EF Core 数据库提供程序Memory-Optimized Tables support in SQL Server EF Core Database Provider

内存优化表是 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 创建和维护基于模型的数据库(使用迁移EnsureCreated)时,将为这些实体创建内存优化表。When using EF Core to create and maintain a database based on your model (either with migrations or EnsureCreated), a memory-optimized table will be created for these entities.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Blog>().IsMemoryOptimized();
}