1

在现有数据库上使用 PivotRunner 更新现有架构时,我遇到了以下错误。

我不知道为什么 view 可能会返回一个空命令。最可信的案例是什么?如果检查此错误,我的程序也会出现相同的错误,我应该检查什么?

感谢您的回答,

    {System.ArgumentNullException: Value cannot be null.
Parameter name: command
   at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.ExecuteNonQuery(String command, Boolean incrementChangesCount)
   at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.UpdateView(PivotRunnerView view, View existingView)
   at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.Run()
   at CodeFluentAssociationMigration.MigrateAssociationsDB.migrate(String associationModelPath, String connectionString) in C:\MyPath\MyProgram.cs:line 190
   at CodeFluentAssociationMigration.Program.Main(String[] args) in C:\MyPath\MyProgram.cs:line 17
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()}

我在日志文件中的唯一跟踪如下:

[04/04/2016 12:18:47] : Checking unique keys...
[04/04/2016 12:18:47] : Checking views...

编辑:这些是我的数据透视文件的视图元素

  <views>
    <view name="vAccount" schema="Association">
      CREATE VIEW [Association].[vAccount]
      AS
      SELECT [Association].[Account].[Account_AccountId], [Association].[Account].[Account_Label], [Association].[Account].[Account_NumberInt], [Association].[Account].[Account_NumberExt], [Association].[Account].[Account_InitialValue], [Association].[Account].[Account_AccountType_AccountTypeId], [Association].[Account].[Account_AccountCategory_AccountCategoryId], [Association].[Account].[Account_IsUsedByDefault], [Association].[Account].[Account_IsDeactivated], [Association].[Account].[Account_IsReadyForClosure], [Association].[Account].[_rowVersion], [Association].[Account].[_trackCreationTime], [Association].[Account].[_trackLastWriteTime], [Association].[Account].[_trackCreationUser], [Association].[Account].[_trackLastWriteUser]
      FROM [Association].[Account]
    </view>
    <view name="vAccountBalanceHistory" schema="Association">
      CREATE VIEW [Association].[vAccountBalanceHistory]
      AS
      SELECT [Association].[AccountBalanceHistory].[AccountBalanceHistory_AccountBalanceHistoryId], [Association].[AccountBalanceHistory].[AccountBalanceHistory_AccountingPeriod_AccountingPeriodId], [Association].[AccountBalanceHistory].[AccountBalanceHistory_Account_AccountId], [Association].[AccountBalanceHistory].[AccountBalanceHistory_DebitBalance], [Association].[AccountBalanceHistory].[AccountBalanceHistory_CreditBalance], [Association].[AccountBalanceHistory].[_rowVersion], [Association].[AccountBalanceHistory].[_trackCreationTime], [Association].[AccountBalanceHistory].[_trackLastWriteTime], [Association].[AccountBalanceHistory].[_trackCreationUser], [Association].[AccountBalanceHistory].[_trackLastWriteUser]
      FROM [Association].[AccountBalanceHistory]
    </view>
    <view name="vAccountCategory" schema="Association">
      CREATE VIEW [Association].[vAccountCategory]
      AS
      SELECT [Association].[AccountCategory].[AccountCategory_AccountCategoryId], [Association].[AccountCategory].[AccountCategory_Number], [Association].[AccountCategory].[AccountCategory_Label], [Association].[AccountCategory].[_rowVersion], [Association].[AccountCategory].[_trackCreationTime], [Association].[AccountCategory].[_trackLastWriteTime], [Association].[AccountCategory].[_trackCreationUser], [Association].[AccountCategory].[_trackLastWriteUser]
      FROM [Association].[AccountCategory]
    </view>
    <view name="vAccountingEntry" schema="Association">
      CREATE VIEW [Association].[vAccountingEntry]
      AS
      SELECT [Association].[AccountingEntry].[AccountingEntry_AccountingEntryId], [Association].[AccountingEntry].[AccountingEntry_Date], [Association].[AccountingEntry].[AccountingEntry_Label], [Association].[AccountingEntry].[AccountingEntry_Debit], [Association].[AccountingEntry].[AccountingEntry_Credit], [Association].[AccountingEntry].[AccountingEntry_DocumentNumber], [Association].[AccountingEntry].[AccountingEntry_Account_AccountId], [Association].[AccountingEntry].[AccountingEntry_TVA_TVAId], [Association].[AccountingEntry].[AccountingEntry_PaymentMode], [Association].[AccountingEntry].[AccountingEntry_LabelAdditional], [Association].[AccountingEntry].[AccountingEntry_Status], [Association].[AccountingEntry].[AccountingEntry_EntryType], [Association].[AccountingEntry].[_rowVersion], [Association].[AccountingEntry].[_trackCreationTime], [Association].[AccountingEntry].[_trackLastWriteTime], [Association].[AccountingEntry].[_trackCreationUser], [Association].[AccountingEntry].[_trackLastWriteUser]
      FROM [Association].[AccountingEntry]
    </view>
    <view name="vAccountingPeriod" schema="Association">
      CREATE VIEW [Association].[vAccountingPeriod]
      AS
      SELECT [Association].[AccountingPeriod].[AccountingPeriod_AccountingPeriodId], [Association].[AccountingPeriod].[AccountingPeriod_DateStart], [Association].[AccountingPeriod].[AccountingPeriod_DateEnd], [Association].[AccountingPeriod].[AccountingPeriod_IsClosed], [Association].[AccountingPeriod].[AccountingPeriod_LedgerURL], [Association].[AccountingPeriod].[AccountingPeriod_BalanceURL], [Association].[AccountingPeriod].[AccountingPeriod_ProfitAndLossURL], [Association].[AccountingPeriod].[_rowVersion], [Association].[AccountingPeriod].[_trackCreationTime], [Association].[AccountingPeriod].[_trackLastWriteTime], [Association].[AccountingPeriod].[_trackCreationUser], [Association].[AccountingPeriod].[_trackLastWriteUser]
      FROM [Association].[AccountingPeriod]
    </view>
    <view name="vAccountType" schema="Association">
      CREATE VIEW [Association].[vAccountType]
      AS
      SELECT [Association].[AccountType].[AccountType_AccountTypeId], [Association].[AccountType].[AccountType_Label], [Association].[AccountType].[AccountType_Group], [Association].[AccountType].[_rowVersion], [Association].[AccountType].[_trackCreationTime], [Association].[AccountType].[_trackLastWriteTime], [Association].[AccountType].[_trackCreationUser], [Association].[AccountType].[_trackLastWriteUser]
      FROM [Association].[AccountType]
    </view>
    <view name="vAssociation" schema="Global">
      CREATE VIEW [Global].[vAssociation]
      AS
      SELECT [Global].[Association].[Association_AssociationId], [Global].[Association].[Association_PrefectureNumber], [Global].[Association].[Association_NumberExt], [Global].[Association].[Association_Label], [Global].[Association].[Association_IsActive], [Global].[Association].[Association_Schema], [Global].[Association].[_rowVersion], [Global].[Association].[_trackCreationTime], [Global].[Association].[_trackLastWriteTime], [Global].[Association].[_trackCreationUser], [Global].[Association].[_trackLastWriteUser]
      FROM [Global].[Association]
    </view>
    <view name="vAssociationUser" schema="Global">
      CREATE VIEW [Global].[vAssociationUser]
      AS
      SELECT [Global].[AssociationUser].[AssociationUser_UserId], [Global].[AssociationUser].[AssociationUser_Association_AssociationId], [Global].[AssociationUser].[_rowVersion], [Global].[AssociationUser].[_trackCreationTime], [Global].[AssociationUser].[_trackLastWriteTime], [Global].[AssociationUser].[_trackCreationUser], [Global].[AssociationUser].[_trackLastWriteUser]
      FROM [Global].[AssociationUser]
    </view>
    <view name="vCardPeriod" schema="Global">
      CREATE VIEW [Global].[vCardPeriod]
      AS
      SELECT [Global].[CardPeriod].[CardPeriod_CardPeriodId], [Global].[CardPeriod].[CardPeriod_FromDate], [Global].[CardPeriod].[CardPeriod_ToDate], [Global].[CardPeriod].[CardPeriod_Season], [Global].[CardPeriod].[CardPeriod_TransferDate], [Global].[CardPeriod].[_rowVersion], [Global].[CardPeriod].[_trackCreationTime], [Global].[CardPeriod].[_trackLastWriteTime], [Global].[CardPeriod].[_trackCreationUser], [Global].[CardPeriod].[_trackLastWriteUser]
      FROM [Global].[CardPeriod]
    </view>
    <view name="vSupplier" schema="Global">
      CREATE VIEW [Global].[vSupplier]
      AS
      SELECT [Global].[Supplier].[Supplier_SupplierId], [Global].[Supplier].[Supplier_Label], [Global].[Supplier].[Supplier_NumberExt], [Global].[Supplier].[_rowVersion], [Global].[Supplier].[_trackCreationTime], [Global].[Supplier].[_trackLastWriteTime], [Global].[Supplier].[_trackCreationUser], [Global].[Supplier].[_trackLastWriteUser]
      FROM [Global].[Supplier]
    </view>
    <view name="vTVA" schema="Association">
      CREATE VIEW [Association].[vTVA]
      AS
      SELECT [Association].[TVA].[TVA_TVAId], [Association].[TVA].[TVA_DateStart], [Association].[TVA].[TVA_DateEnd], [Association].[TVA].[TVA_Rate], [Association].[TVA].[_rowVersion], [Association].[TVA].[_trackCreationTime], [Association].[TVA].[_trackLastWriteTime], [Association].[TVA].[_trackCreationUser], [Association].[TVA].[_trackLastWriteUser]
      FROM [Association].[TVA]
    </view>
  </views>
4

1 回答 1

1

看起来您已经格式化了 xml 文档。视图的定义现在以一个新行和一些空格开始,并且枢轴转轮不喜欢它。有2个解决方案:

  • 不要更改生成的文件(最简单的解决方案)
  • 使用下面提供的自定义枢轴运行器来修剪定义

在这段代码中,我们创建了一个继承自 的类,PivotRunner并更改了视图、过程和函数的定义。

using CodeFluent.Runtime;
using CodeFluent.Runtime.Database.Management.SqlServer;
using System;
using System.Xml;

public class CustomPivotRunner : PivotRunner
{
    public CustomPivotRunner(string packageFilePath) : base(packageFilePath)
    {
    }

    protected override PivotRunnerProcedure NewProcedure(XmlElement element)
    {
        return new CustomPivotRunnerProcedure(this, element);
    }

    protected override PivotRunnerView NewView(XmlElement element)
    {
        return new CustomPivotRunnerView(this, element);
    }

    protected override PivotRunnerFunction NewFunction(XmlElement element)
    {
        return new CustomPivotRunnerFunction(this, element);
    }
}

public class CustomPivotRunnerProcedure : PivotRunnerProcedure
{
    public CustomPivotRunnerProcedure(PivotRunner runner, XmlElement element) : base(runner, element)
    {
        Definition = Definition?.Trim();
    }
}

public class CustomPivotRunnerFunction : PivotRunnerFunction
{
    public CustomPivotRunnerFunction(PivotRunner runner, XmlElement element) : base(runner, element)
    {
        Definition = Definition?.Trim();
    }
}

public class CustomPivotRunnerView : PivotRunnerView
{
    public CustomPivotRunnerView(PivotRunner runner, XmlElement element) : base(runner, element)
    {
        Definition = Definition?.Trim();
    }
}

class Program
{
    static void Main(string[] args)
    {
        var logger = new Logger();
        PivotRunner pivotRunner = new CustomPivotRunner(@"MyModelpivot.xml");
        pivotRunner.ConnectionString = CodeFluentContext.Get("Sample").Persistence.ConnectionString;
        pivotRunner.Logger = logger;
        pivotRunner.Action += PivotRunner_Action;
        pivotRunner.Run();
    }

    private static void PivotRunner_Action(object sender, PivotRunnerEventArgs e)
    {
        Console.WriteLine(e.Type + " " + e.Options);
    }

    public class Logger : IServiceHost
    {
        public void Log(object value)
        {
            Console.WriteLine(value);
        }
    }
}
于 2016-04-05T12:28:21.403 回答