我继承了一个使用FluentMigrator管理迁移的项目.最初,该项目在应用程序启动时正在执行迁移,但IT部门已经对此进行了打击,现在我们必须向DBA提供脚本以进行所有数据库更改.
作为此转换的一部分,我已将迁移移至名为Migrations的新项目.当我尝试使用命令行工具执行迁移时,它似乎可以工作,但是没有迁移应用于数据库.数据库字符串是正确的,因为如果VersionInfo表不存在则会创建它.
有许多迁移,但大多数都非常简单.以下是第一个示例:

我正在使用SQL Server 2012和FluentMigrator 1.2.1.
这是gunr2171的文本命令行:
.\Packages\FluentMigrator.1.2.1.0\tools\migrate.exe -c "Data Source=.;Integrated Security=True;Initial Catalog=portal_test" -db sqlserver2012 -a .\source\Migrations\bin\Debug\migrations.dll
Run Code Online (Sandbox Code Playgroud)
示例迁移:
using System;
using System.Collections.Generic;
using System.Linq;
using FluentMigrator;
namespace Migrations
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores")]
[Migration(1)]
public class M001_CreateAccountTable : Migration
{
public override void Up()
{
Create.Table("Accounts")
.WithColumn("Id").AsInt32().NotNullable().Identity().Unique()
.WithColumn("PartnerCode").AsString().Nullable()
.WithColumn("AccountType").AsInt32().NotNullable()
.WithColumn("Code").AsString().NotNullable().Unique().PrimaryKey()
.WithColumn("Name").AsString().NotNullable()
.WithColumn("PrimaryDomainName").AsString().Nullable()
.WithColumn("IsFederated").AsBoolean().NotNullable()
.WithColumn("IsActive").AsBoolean().Nullable().WithDefaultValue(1)
.WithColumn("FederatedEndpoint").AsString().Nullable()
.WithColumn("CreatedBy").AsString().NotNullable()
.WithColumn("CreatedOn").AsDateTime().NotNullable().WithDefaultValue(DateTime.Now)
.WithColumn("ModifiedBy").AsString().NotNullable()
.WithColumn("ModifiedOn").AsDateTime().NotNullable().WithDefaultValue(DateTime.Now);
}
public override void Down()
{
Delete.Table("Accounts");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个课程,呼吁互联网服务获取一些数据:
public class MarketingService
{
private IDataProvider _provider;
public MarketingService(IDataProvider provider)
{
_provider = provider;
}
public string GetData(int id)
{
return _provider.Get(id);
}
}
Run Code Online (Sandbox Code Playgroud)
目前我有两个提供程序:HttpDataProvider和FileDataProvider.通常我会连接到HttpDataProvider,但如果外部Web服务失败,我想更改系统以绑定到FileDataProvider.就像是:
public string GetData(int id)
{
string result = "";
try
{
result = GetData(id); // call to HttpDataProvider
}
catch (Exception)
{
// change the Windsor binding so that all future calls go automatically to the
// FileDataProvier
// And while I'm at it, retry against the FileDataProvider
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
因此,当执行此操作时,所有将来的MarketingService实例都将自动连接到FileDataProvider.如何在飞行中更改Windsor绑定?
我有一个应用程序,它使用计时器偶尔在辅助线程上运行监视任务.其中一些清理任务需要花费大量时间,我希望能够在用户结束程序时中止这些任务(如果可能的话,优雅地).
是否有任何方法可以使用Thread.Abort()以编程方式中止线程,或者我是否必须在代码中添加一个标志以指示线程已完成并在启动的代码中的有害位置检查通过计时器?
我不小心从源目录中删除了一些文件.我需要重新获取整个git存储库(git pull不起作用,因为自上次提交后这些文件没有更改).我的存储库是最新的.我如何获得整个存储库?如果它覆盖那里的东西就没关系
我正在为我的.NET Core项目构建自动化集成测试.不知何故,我需要访问我的集成测试数据库的连接字符串.新的.net核心不再具有ConfigurationManager,而是注入了配置,但是没有办法(至少不是我所知道的)将连接字符串注入到测试类中.
在.NET Core中是否有任何方法可以在配置文件中获取而无需将某些内容注入测试类?或者,或者,测试类是否有任何方式可以将依赖项注入其中?
我正在尝试使用我的项目中的settings.settings文件.需要在.exe文件和各种DLL之间共享值.我宁愿不仅仅传递这些值,我想在需要时访问它们,但是每个项目都会设置其名称略有不同的值,因此其他项目无法访问它们.
有没有办法使用settings.settings方法在.exe和.dll之间共享app.config文件的内容?或者我是否需要返回使用ConfigurationManager才能执行此操作?
我目前正在构建一个使用MassTransit和RabbitMQ作为我的消息传递层的系统.我正试图找到一种方法让一个消费者监听总线上所有类型的所有消息.这适用于我们的审计日志记录框架,我们希望记录通过消息总线的所有事件.
有没有办法在MassTransit中这样做?
我有一个有两种不同实现的接口.
public interface IProducer
{
}
public class Producer : IProducer
{
}
public class FaultProducer : IProducer
{
}
Run Code Online (Sandbox Code Playgroud)
我有两个不同的类,它们都将IProducer作为依赖项.
public class ConsumerChannel
{
public ConsumerChannel(IProducer producer)
{
}
}
public class TradePublisher
{
public TradePublisher(IProducer producer)
{
}
}
Run Code Online (Sandbox Code Playgroud)
TradePublisher需要一个制作人,ConsumerChannel需要一个FaultProducer.我只能绑定IProducer到一个实现.在温莎我可以使用命名绑定来做到这一点,Dependency.OnComponent但我在Ninject中找不到类似的能力.有没有办法在Ninject中注入特定的依赖项?
是否有Linq运算符可确保集合的最小大小
我想看到的是:
int[] x = {1, 2, 3, 4};
var y = x.Fill(6);
// y is now {1, 2, 3, 4, 0, 0}
Run Code Online (Sandbox Code Playgroud)
注意(到目前为止的答案)我正在寻找可以使用的东西IEnumerable<T>. int[]只是为了在示例中轻松初始化