Pivot Runner null command

后端 未结 1 1025
甜味超标
甜味超标 2021-01-24 08:53

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.

相关标签:
1条回答
  • 2021-01-24 09:11

    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:

    • Don't change the generated file (the easiest solution)
    • Use a custom pivot runner as provided below that trims the definitions

    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);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题