我正在使用 .NET 6 和 PostgreSQL 数据库。
我有一个
hosted service
,它定期调用 repository's function
并且 querying database entities
使用 EF Core
,如下所示:
public class NotificationRepository : INotificationRepository
{
public async Task<List<Notification>> GetUnreadDeviceNotifications()
{
using var context = new MyDbContext();
return await context.Notifications.Where(x => !x.IsSentTimestamp.HasValue && x.ChannelId == 8).ToListAsync();
}
}
一旦我在
linux
机器上部署并且每次服务调用 GetUnreadDeviceNotifications
时,我都会收到此错误:
Aug 07 12:50:46 my-app my-app.Web[1432629]: System.IO.FileNotFoundException: Could not load file or assembly 'Npgsql, Version=6.0.8.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'. The system cannot find the file specified.
Aug 07 12:50:46 my-app my-app.Web[1432629]: File name: 'Npgsql, Version=6.0.8.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'
Aug 07 12:50:46 my-app my-app.Web[1432629]: at Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.NpgsqlOptionsExtension.ExtensionInfo.GetServiceProviderHashCode()
Aug 07 12:50:46 my-app my-app.Web[1432629]: at Microsoft.EntityFrameworkCore.DbContextOptions.GetHashCode()
Aug 07 12:50:46 my-app my-app.Web[1432629]: at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
Aug 07 12:50:46 my-app my-app.Web[1432629]: at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
Aug 07 12:50:46 my-app my-app.Web[1432629]: at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
Aug 07 12:50:46 my-app my-app.Web[1432629]: at Microsoft.EntityFrameworkCore.DbContext.get_Model()
Aug 07 12:50:46 my-app my-app.Web[1432629]: at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType()
Aug 07 12:50:46 my-app my-app.Web[1432629]: at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable()
Aug 07 12:50:46 my-app my-app.Web[1432629]: at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Linq.IQueryable.get_Provider()
Aug 07 12:50:46 my-app my-app.Web[1432629]: at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
Aug 07 12:50:46 my-app my-app.Web[1432629]: at my-app.Infrastructure.Repositories.NotificationRepository.GetUnreadDeviceNotifications() in C:\Projects\my-app\src\my-app.Infrastructure\Repositories\NotificationRepository.cs:line 22
Aug 07 12:50:46 my-app my-app.Web[1432629]: at my-app.Application.Services.MessagingServices.NotificationReadingService.DoWork(Object state) in C:\Projects\my-app\src\my-app.Application\Services\MessagingServices\NotificationReadingService.cs:line 35
这些是
dependencies
我有:
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Npgsql" Version="6.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.3" />
</ItemGroup>
附注看起来效果很好
Windows