2017-05-31 32 views
0

我一直在试图让IdentityServer4版本1.5.2工作几天没有成功。我正在使用VS2017 My Entity类,DataContexts,存储库和迁移驻留在.Net标准库(1.6)中。到目前为止,除了当我为“PersistenGrantDbContext”和“ConfigurationDbCOntext”运行update-migration命令时,这是非常好的。我得到的错误信息更新迁移命令失败ConfigurationDbContext和PersistentGrantDbContext

Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. 

,我创建自己似乎没有执行“IDbContextFactory”界面 这里我有两个匪徒实施后有这个问题在DataContext类

public class TemporaryDbContextFactoryScopes : IDbContextFactory<PersistedGrantDbContext> 
{ 
    public PersistedGrantDbContext Create(DbContextFactoryOptions options) 
    { 
     var builder = new DbContextOptionsBuilder<PersistedGrantDbContext>(); 
     builder.UseSqlServer("Server=-------;Database=-----------;Trusted_Connection=True;MultipleActiveResultSets=true", 
      optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(UserDbContext).GetTypeInfo().Assembly.GetName().Name)); 
     return new PersistedGrantDbContext(builder.Options, new OperationalStoreOptions()); 
    } 
} 

public class TemporaryDbContextFactoryOperational : IDbContextFactory<ConfigurationDbContext> 
{ 
    public ConfigurationDbContext Create(DbContextFactoryOptions options) 
    { 
     var builder = new DbContextOptionsBuilder<ConfigurationDbContext>(); 
     builder.UseSqlServer("Server=---------;Database=--------;Trusted_Connection=True;MultipleActiveResultSets=true", 
      optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(UserDbContext).GetTypeInfo().Assembly.GetName().Name)); 

     return new ConfigurationDbContext(builder.Options, new ConfigurationStoreOptions()); 
    } 
} 

我有安装最新版本的System.Data.SqlClient仍然不能正常工作

+0

而最新的一个版本号是4.1.0.0,如错误报告? – Mashton

+0

没有最新版本是4.3.1,但我设法通过非正统手段解决它 –

回答

0

只是想分享我所做的事情,让事情滚动。不知道这是虽然 首先我类库中的.csproj

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" /> 
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.1" /> 

现在竟然是一个坏主意,因为这是抛出这个错误没有它运行我的迁移与这样做是正确的方法我Web应用程序作为我开始了项目返回错误“没有背景等等等等用的名字等等等等找到” 所以我意识到,我创造了自己的工作没有毛刺,所以我没有这PersistentGrantDBCOntext和COnfigurationGrantDbContext

public class PGrantDbContext: PersistedGrantDbContext 
{ 
    public PGrantDbContext(DbContextOptions<PersistedGrantDbContext> options, OperationalStoreOptions storeOptions) : base(options, storeOptions) 
    { 

    } 
} 

上下文
public ConfigDbContext(DbContextOptions<ConfigurationDbContext> options, ConfigurationStoreOptions storeOptions):base(options,storeOptions) 
    { 

    } 

一切都很顺利。 只是不太确定是否是正确的做法虽然

+0

我有以下问题:'PGrantDbContext'上没有找到无参数的构造函数。在'PGrantDbContext'中添加无参数构造函数,或者在与'PGrantDbContext'相同的程序集中添加'IDbContextFactory '实现。你是如何解决它的? – CoffeeCode

0

几周前我也处于类似的情况,这是我如何解决它。

与您非常相似,我有两个名为Company.Identity.NETCoreApp)的项目作为我的Identity项目和Company.Identity.Data.NETStandard 1.6)进行迁移。我使用Company.Identity Project作为迁移目的的启动项目,因为它与我的数据项目处于相同的解决方案,并且我不想将另一个项目的解决方案与迁移的启动项目混为一谈。

我按照教程here

cli工具参考<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />在我的Company.Identity.csproj文件中。

我接着在除了以下区别

Company.IdentityStartupConfigureServices方法上面的教程的所有步骤,我已经设置了migrationsAssemblyCompany.Identity.Data

var migrationsAssembly = "Company.Identity.Data"; 

注意Company.Identity项目已经安装了IdentityServer4.EntityFramework nuget软件包。这使我能够为PersistedGrantDbContext添加迁移。但是,当我试图运行迁移ConfigurationDbContext它给了我一个构建错误。这是因为PersistedGrantDbContext生成的迁移需要IdentityServer4.EntityFramework nuget包。所以我不得不在Company.Identity.Data project

我可以通过在我的Company.Identity项目中的命令提示符进行上述更改后使用以下命令来添加迁移。

dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Migrations/IdentityServer/PersistedGrantDb -p ../Company.Identity.Data 

dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Migrations/IdentityServer/ConfigurationDb -p ../Company.Identity.Data 

希望帮助