コード例 #1
0
        internal new static CalculatedTable CreateFromMetadata(Model parent, TOM.Table metadataObject)
        {
            if (metadataObject.GetSourceType() != TOM.PartitionSourceType.Calculated)
            {
                throw new ArgumentException("Provided metadataObject is not a Calculated Table.");
            }

            // Generate a new LineageTag if an object with the provided lineage tag already exists:
            if (!string.IsNullOrEmpty(metadataObject.LineageTag))
            {
                if (parent.Handler.CompatibilityLevel < 1540)
                {
                    metadataObject.LineageTag = null;
                }
                else if (parent.MetadataObject.Tables.FindByLineageTag(metadataObject.LineageTag) != metadataObject)
                {
                    metadataObject.LineageTag = Guid.NewGuid().ToString();
                }
            }
            var obj = new CalculatedTable(metadataObject);

            parent.Tables.Add(obj);

            obj.Init();

            return(obj);
        }
コード例 #2
0
        /// <summary>
        /// Creates a new Calculated Table and adds it to the specified Model.
        /// Also creates the underlying metadataobject and adds it to the TOM tree.
        /// </summary>
        public static CalculatedTable CreateNew(Model parent, string name = null, string expression = null)
        {
            var metadataObject = new TOM.Table();

            if (parent.Model.Database.CompatibilityLevel >= 1540)
            {
                metadataObject.LineageTag = Guid.NewGuid().ToString();
            }
            metadataObject.Name = parent.Tables.GetNewName(string.IsNullOrWhiteSpace(name) ? "New Calculated Table" : name);
            var tomPartition = new TOM.Partition();

            tomPartition.Mode   = TOM.ModeType.Import;
            tomPartition.Name   = metadataObject.Name;
            tomPartition.Source = new TOM.CalculatedPartitionSource();
            metadataObject.Partitions.Add(tomPartition);
            var obj = new CalculatedTable(metadataObject);

            parent.Tables.Add(obj);
            obj.Init();

            if (!string.IsNullOrWhiteSpace(expression))
            {
                obj.Expression = expression;
            }

            return(obj);
        }
コード例 #3
0
        public CalculatedTable AddCalculatedTable(string name = null, string expression = null)
        {
            Handler.BeginUpdate("add calculated table");
            var t = CalculatedTable.CreateNew(this, name, expression);

            Handler.EndUpdate();
            return(t);
        }
コード例 #4
0
        internal static void CreateCalculatedTablePartition(CalculatedTable calcTable)
        {
            var tomPartition = new TOM.Partition();

            tomPartition.Name = calcTable.Name;
            var partition = new Partition(tomPartition);

            calcTable.Partitions.Add(partition);
            partition.Init();
            partition.MetadataObject.Source = new TOM.CalculatedPartitionSource();
        }
コード例 #5
0
ファイル: Model.cs プロジェクト: ywscr/TabularEditor
        public CalculatedTable AddCalculatedTable(string name = null, string expression = null)
        {
            if (!Handler.PowerBIGovernance.AllowCreate(typeof(CalculatedTable)))
            {
                throw new PowerBIGovernanceException("Adding Calculated Tables to this Power BI model is not supported.");
            }

            Handler.BeginUpdate("add calculated table");
            var t = CalculatedTable.CreateNew(this, name, expression);

            Handler.EndUpdate();
            return(t);
        }
コード例 #6
0
        internal new static CalculatedTable CreateFromMetadata(Model parent, TOM.Table metadataObject)
        {
            if (metadataObject.GetSourceType() != TOM.PartitionSourceType.Calculated)
            {
                throw new ArgumentException("Provided metadataObject is not a Calculated Table.");
            }
            var obj = new CalculatedTable(metadataObject);

            parent.Tables.Add(obj);

            obj.Init();

            return(obj);
        }
コード例 #7
0
        /// <summary>
        /// Creates a new Calculated Table and adds it to the specified Model.
        /// Also creates the underlying metadataobject and adds it to the TOM tree.
        /// </summary>
        public static CalculatedTable CreateNew(Model parent, string name = null, string expression = null)
        {
            var metadataObject = new TOM.Table();

            metadataObject.Name = parent.Tables.GetNewName(string.IsNullOrWhiteSpace(name) ? "New Calculated Table" : name);

            var obj = new CalculatedTable(metadataObject);

            parent.Tables.Add(obj);
            obj.Init();

            if (!string.IsNullOrWhiteSpace(expression))
            {
                obj.Expression = expression;
            }

            return(obj);
        }
コード例 #8
0
        /// <summary>
        /// Creates a new Calculated Table and adds it to the specified Model.
        /// Also creates the underlying metadataobject and adds it to the TOM tree.
        /// </summary>
        public static CalculatedTable CreateNew(Model parent, string name = null, string expression = null)
        {
            var metadataObject = new TOM.Table();

            metadataObject.Name = parent.Tables.GetNewName(string.IsNullOrWhiteSpace(name) ? "New Calculated Table" : name);
            var tomPartition = new TOM.Partition();

            tomPartition.Mode   = TOM.ModeType.Import;
            tomPartition.Name   = metadataObject.Name;
            tomPartition.Source = new TOM.CalculatedPartitionSource();
            metadataObject.Partitions.Add(tomPartition);
            var obj = new CalculatedTable(metadataObject);

            parent.Tables.Add(obj);
            obj.Init();

            if (!string.IsNullOrWhiteSpace(expression))
            {
                obj.Expression = expression;
            }

            return(obj);
        }