-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EF Core+ Code First迁移时报错,会是什么问题呢? #284
Comments
@lampo1024 efcore几 shardingcore几 配置可以发一下吗 |
以下是项目配置: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="ShardingCore" Version="7.8.1.22" />
</ItemGroup>
</Project> |
@lampo1024 再等会可以吗 efcore9目前还没适配,可以先用8我最近有空了会支持9,年底了比较忙一直没有太多时间 |
行,我把版本降低一点试试 |
降低版本之后也有问题: pwshdotnet ef migrations add InitialCreate
Build started...
Build succeeded.
Unable to create a 'DbContext' of type 'RuntimeType'. The exception 'Method 'get_LockReleaseBehavior' in type 'Microsoft.EntityFrameworkCore.SqlServer.Migrations.Internal.SqlServerHistoryRepository' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=8.0.11.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
pwshdotnet ef migrations add InitialCreate
Build started...
Build succeeded.
Unable to create a 'DbContext' of type 'RuntimeType'. The exception 'Method 'get_LockReleaseBehavior' in type 'Microsoft.EntityFrameworkCore.SqlServer.Migrations.Internal.SqlServerHistoryRepository' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=7.0.20.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 |
@lampo1024 efcore8吗 |
是的 |
shardingcore的startup配置方便看看吗 |
builder.Services.AddShardingDbContext<ReportContext>().UseRouteConfig(builder =>
{
builder.AddShardingDataSourceRoute<SpecimenReportsVirtualTableRoute>();
}).UseConfig(op =>
{
ILoggerFactory efLogger = LoggerFactory.Create(builder =>
{
builder.AddFilter((category, level) => category == DbLoggerCategory.Database.Command.Name && level == LogLevel.Information).AddConsole();
});
op.UseShardingQuery((conStr, builder) =>
{
builder.UseSqlServer(conStr).UseLoggerFactory(efLogger);
});
op.UseShardingTransaction((connection, builder) =>
{
builder.UseSqlServer(connection).UseLoggerFactory(efLogger);
});
op.AddDefaultDataSource("2020", "Server=localhost;Database=ReportDB2020;UID=sa;PWD=123;TrustServerCertificate=True;");
op.AddExtraDataSource(sp =>
{
var dbs = new Dictionary<string, string> {
{ "2023","Server=localhost;Database=ReportDB2023;UID=sa;PWD=123;TrustServerCertificate=True;"},
{ "202x","Server=localhost;Database=ReportDB202x;UID=sa;PWD=123;TrustServerCertificate=True;"}
};
return dbs;
});
}).AddShardingCore(); |
@lampo1024 目前来看缺少一个useShardingMigrationConfigure,但是我不确定是不是这个问题导致的 |
我加上试试 |
嗯还是不行的话,如果可以方便给一个最小demo吗 |
晚些时候或者明天我给个demo给你 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用
dotnet ef migrations add InitialCreate
迁移时报错,如下:Build started...
Build succeeded.
System.MissingMethodException: Method not found: 'Void Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator..ctor(Microsoft.EntityFrameworkCore.Migrations.IMigrationsAssembly, Microsoft.EntityFrameworkCore.Migrations.IHistoryRepository, Microsoft.EntityFrameworkCore.Storage.IDatabaseCreator, Microsoft.EntityFrameworkCore.Migrations.IMigrationsSqlGenerator, Microsoft.EntityFrameworkCore.Storage.IRawSqlCommandBuilder, Microsoft.EntityFrameworkCore.Migrations.IMigrationCommandExecutor, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection, Microsoft.EntityFrameworkCore.Storage.ISqlGenerationHelper, Microsoft.EntityFrameworkCore.Infrastructure.ICurrentDbContext, Microsoft.EntityFrameworkCore.Infrastructure.IModelRuntimeInitializer, Microsoft.EntityFrameworkCore.Diagnostics.IDiagnosticsLogger
1<Migrations>, Microsoft.EntityFrameworkCore.Diagnostics.IRelationalCommandDiagnosticsLogger, Microsoft.EntityFrameworkCore.Storage.IDatabaseProvider)'. at ShardingCore.EFCores.ShardingMigrator..ctor(IShardingRuntimeContext shardingRuntimeContext, IMigrationsAssembly migrationsAssembly, IHistoryRepository historyRepository, IDatabaseCreator databaseCreator, IMigrationsSqlGenerator migrationsSqlGenerator, IRawSqlCommandBuilder rawSqlCommandBuilder, IMigrationCommandExecutor migrationCommandExecutor, IRelationalConnection connection, ISqlGenerationHelper sqlGenerationHelper, ICurrentDbContext currentContext, IModelRuntimeInitializer modelRuntimeInitializer, IDiagnosticsLogger
1 logger, IRelationalCommandDiagnosticsLogger commandLogger, IDatabaseProvider databaseProvider)......
会是什么问题呢?
The text was updated successfully, but these errors were encountered: