首页 > 解决方案 > 如何使用实体框架核心为 postgress 数据库安装 TimescaleDB 扩展

问题描述

我想在包含时间序列数据的特定表上使用TimescaleDB 。我的问题是如何从实体框架核心设置时间序列并使特定表成为超表

数据库:Postgress 版本 11 框架:Ef Core 2.2 方法:代码优先

标签: postgresqlef-core-2.2timescaledb

解决方案


这是代码优先 EF 的解决方案。这很简单。

1) 在要使用 timescale db 缩放的表模型中添加一个日期时间字段。

2) 为 Postgres 安装 timescale 插件。

CREATE EXTENSION timescaledb;

3) 在数据库播种器或初始化程序中执行以下 SQL。

dbcontext.Database.ExecuteSqlCommand("SELECT create_hypertable('table_name', 'datetime_field_name');");

datetime_field_name是 timescale db 的必填日期时间字段(参见 1))


推荐阅读