npgsql

在ef core中使用postgres数据库的全文检索功能实战

元气小坏坏 提交于 2020-07-28 20:12:36
起源 之前做的很多项目都使用solr/elasticsearch作为全文检索引擎,它们功能全面而强大,但是对于较小的项目而言,构建和维护成本显然过高,尤其是从关系数据库/文档数据库到全文检索引擎的数据同步工作非常繁琐,且容易出错。 记得很久以前就知道postgresql数据库内置全文检索,最近发现这个数据库越来越火,于是就又研究了一番,欣喜的发现居然支持ef core,于是对其进行了一些研究,并整理心得如下。 前提 本文假设读者熟悉entity framework core的基本概念和基本使用。 目的 建立dotnet core项目,使用postgres数据库和ef core,实现常见的全文检索功能,包括 建立索引字段 基本查询 查询结果排名 查询结果高亮显示 步骤1 - 新建项目并引入packages < Project Sdk ="Microsoft.NET.Sdk" > < PropertyGroup > < OutputType > Exe </ OutputType > < TargetFramework > netcoreapp3.1 </ TargetFramework > </ PropertyGroup > < ItemGroup > < PackageReference Include ="EFCore.NamingConventions" Version =

Message “28000: no pg_hba.conf entry for host \”xx.xxx.xxx.xxxx\“, user \”User“, database \”databasename\“, SSL off”

元气小坏坏 提交于 2020-07-20 11:44:12
问题 I 'm trying to connect postgresql database remotely ( Heroku ). I use ASP Web api but always i have the same exception :Message "28000: no pg_hba.conf entry for host \"xx.xxx.xxx.xxxx\", user \"User", database \"databasename\", SSL off" I search some solution by editing the pg_hba.conf file and i add : host databasename username xx.xxx.xxx.xxxx md5 and no change . 回答1: Add sslmode=Require; and Trust Server Certificate=true; in your connection string.It will work for sure. 回答2: Heroku Postgres

PostgresException: 23505: duplicate key value violates unique constraint “PK_country”

点点圈 提交于 2020-07-18 20:58:20
问题 I am using EF Core 2.0 and Postgres 9.6. Whenever I insert data I get the error PostgresException: 23505: duplicate key value violates unique constraint "PK_country" By tracing it looks like EF doesnt generate AutoIncrement column My Model public partial class Country { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int CountryId { get; set; } [Display(Name="Country Name")] public string CountryName { get; set; } } My Controller if (ModelState.IsValid) { _context.Add

PostgresException: 23505: duplicate key value violates unique constraint “PK_country”

烈酒焚心 提交于 2020-07-18 20:57:04
问题 I am using EF Core 2.0 and Postgres 9.6. Whenever I insert data I get the error PostgresException: 23505: duplicate key value violates unique constraint "PK_country" By tracing it looks like EF doesnt generate AutoIncrement column My Model public partial class Country { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int CountryId { get; set; } [Display(Name="Country Name")] public string CountryName { get; set; } } My Controller if (ModelState.IsValid) { _context.Add