asp.net - Npgsql: What does `AddEntityFrameworkNpgsqlTrigrams` do?
问题描述
Since Ngpsql docs doesn't have a comperhensive page for fuzzy string matching, I went with what test cases are using, and got the following error:
Exception has occurred: CLR/System.AggregateException An unhandled exception of type 'System.AggregateException' occurred in API.dll: 'Some services are not able to be constructed' Inner exceptions found, see $exception in variables window for more details. Innermost exception System.InvalidOperationException : Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.IRelationalTypeMappingSource' while attempting to activate 'Npgsql.EntityFrameworkCore. PostgreSQL.Query.ExpressionTranslators.Internal.NpgsqlTrigramsMethodCallTranslatorPlugin'. at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceDescriptor serviceDescriptor, CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor)
Normally I'd ask what's happening, but I've noticed that if I don't use AddEntityFrameworkNpgsqlTrigrams, I'm able to compile and my call to a trigram function (TrigramsSimilarity to be exact) results in my expression being translated successfully. So my question is: What is AddEntityFrameworkNpgsqlTrigrams for? Can I leave it out?
I should note that I'm using Npgsql.EntityFrameworkCore.PostgreSQL.Trigrams version 3.1.4. We haven't migrated to .NET 5.0
解决方案
使用Trigram插件的常用方法是参考Npgsql.EntityFrameworkCore.PostgreSQL.Trigrams nuget 包,并在您的:OnModelConfiguring
options.UseNpgsql(@"<connection string>", o => o.UseTrigrams())
这在此处记录。应用程序很少需要直接调用 AddEntityFrameworkNpgsqlTrigrams。
推荐阅读
- web - Intellij IDEA Ultimate Java EE
- sql - Oracle SQL 组合多个查询的非重复结果
- r - 在函数-ggplot中将参数传递给构面网格
- optimization - pytorch中序数多分类的损失函数
- javascript - Asp.Net 显示与 $ajax 一起使用的默认错误页面
- airflow - 如何获得上一份工作的结束时间
- kubernetes - 错误:(gcloud.compute.instance-templates.create)无法获取图像资源:
- php - 在找不到记录时插入数据,否则使用 PHP Mysql 使用最后插入的 ID 更新上一条记录
- kotlin - 是否可以对网络中的其他节点隐藏某些 corda 节点?
- postgresql - 无法远程连接到 Postgres 服务器