While updating existing schema with PivotRunner on an existing database, I\'m facing the error presented below.
I can\'t figure out why view may return an empty command.
It looks like you have formatted the xml document. The definition of the view now starts with a new line and some spaces, and the pivot runner doesn't like it. There are 2 solutions:
In this code we create a class that inherits from the PivotRunner and we change the definition of views, procedures and functions.
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);
}
}
}