如何解决Npgsql:`AddEntityFrameworkNpgsqlTrigrams` 有什么作用?
由于 Ngpsql 文档没有用于 fuzzy 字符串匹配的 comperhensive page,所以我使用了 test cases 正在使用的内容,并得到以下错误:
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,CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor,Int32 slot) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceDescriptor serviceDescriptor,CallSiteChain callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor)
通常我会问发生了什么,但我注意到如果我不使用 AddEntityFrameworkNpgsqlTrigrams,我可以编译并且我对 trigram 函数(确切地说是 TrigramsSimilarity)的调用会导致我的表达被成功翻译。所以我的问题是:AddEntityFrameworkNpgsqlTrigrams 有什么用?我可以不放吗?
我应该注意到我使用的是 Npgsql.EntityFrameworkCore.PostgreSQL.Trigrams 3.1.4 版。我们还没有迁移到 .NET 5.0
解决方法
使用 Trigram 插件的通常方法是引用 Npgsql.EntityFrameworkCore.PostgreSQL.Trigrams nuget 包,并在您的 OnModelConfiguring
中调用 UseTrigrams:
options.UseNpgsql(@"<connection string>",o => o.UseTrigrams())
This is documented here。应用程序很少需要直接调用 AddEntityFrameworkNpgsqlTrigrams。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。