/// <summary>
        /// Returns a collection of CalculationItem objects filtered by the parent table's name.
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns>CalculationItemCollection</returns>
        public CalculationItemCollection FilterByTableName(string tableName)
        {
            CalculationItemCollection returnCalculationItems = new CalculationItemCollection();

            foreach (CalculationItem calculationItem in this)
            {
                if (calculationItem.TableName == tableName)
                {
                    returnCalculationItems.Add(calculationItem);
                }
            }
            return(returnCalculationItems);
        }
Beispiel #2
0
        private void PopulateProperties()
        {
            base.RemovePropertyFromObjectDefinition("measures");

            _isCalculationGroup   = (_tomTable.CalculationGroup != null);
            _partitionsDefinition = "";
            _dataSourceName       = "";
            bool hasMQueryOrPolicyPartition = false;

            //Associate table with a DataSource if possible. It's not possible if calc table or if M expression refers to a shared expression, or multiple data sources
            foreach (Partition partition in _tomTable.Partitions)
            {
                _tableModeType = partition.Mode;
                if (partition.SourceType == PartitionSourceType.M)
                {
                    hasMQueryOrPolicyPartition = true;

                    //Check M dependency tree to see if all partitions refer only to a single DataSource
                    CalcDependencyCollection calcDependencies = _parentTabularModel.MDependencies.DependenciesReferenceFrom(CalcDependencyObjectType.Partition, _tomTable.Name, partition.Name);

                    if (calcDependencies.Count == 1 && calcDependencies[0].ReferencedObjectType == CalcDependencyObjectType.DataSource)
                    {
                        if (_dataSourceName == "")
                        {
                            _dataSourceName = calcDependencies[0].ReferencedObjectName;
                        }
                        else if (_dataSourceName != calcDependencies[0].ReferencedObjectName)
                        {
                            //Partition depends on a different DataSource to another partition in same table, so ensure no DataSource association for the table and stop iterating partitions.
                            _dataSourceName = "";
                            break;
                        }
                    }
                    else
                    {
                        //Partition has mutiple dependencies, or depends on an expression instead of DataSource, so ensure no DataSource association for the table and stop iterating partitions.
                        _dataSourceName = "";
                        break;
                    }
                }

                //If old partition, find the primary partition (first one) to determine DataSource. Technically it is possible for different partitions in the same table to point to different DataSources, but the Tabular Designer in VS doesn't support it. If set manually in .bim file, the UI still associates with the first partition (e.g. when processing table by itself, or deletinig the DataSource gives a warning message listing associated tables).
                if (partition.SourceType == PartitionSourceType.Query)
                {
                    hasMQueryOrPolicyPartition = true;
                    _dataSourceName            = ((QueryPartitionSource)partition.Source).DataSource.Name;
                    break;
                }

                //Might be a policy partition.
                if (partition.SourceType == PartitionSourceType.PolicyRange)
                {
                    hasMQueryOrPolicyPartition = true;
                    break;
                }
            }

            if (hasMQueryOrPolicyPartition || _isCalculationGroup)
            {
                _partitionsDefinition = base.RetrievePropertyFromObjectDefinition("partitions");

                //Option to hide partitions only applies to M, query and policy partitions (calculated tables hold dax defintitions in their partitions)
                if (!_parentTabularModel.ComparisonInfo.OptionsInfo.OptionPartitions)
                {
                    base.RemovePropertyFromObjectDefinition("partitions");
                }
            }

            //Find table relationships
            foreach (Tom.Relationship relationship in _tomTable.Model.Relationships)
            {
                if (relationship.FromTable.Name == _tomTable.Name && relationship.Type == RelationshipType.SingleColumn)  //currently only support single column
                {
                    _relationships.Add(new Relationship(this, (SingleColumnRelationship)relationship));
                }
            }

            //Find measures
            foreach (Tom.Measure measure in _tomTable.Measures)
            {
                _measures.Add(new Measure(this, measure, measure.KPI != null));
            }

            //Find calc items
            if (_isCalculationGroup)
            {
                foreach (Tom.CalculationItem calcItem in _tomTable.CalculationGroup.CalculationItems)
                {
                    _calculationItems.Add(new CalculationItem(this, calcItem));
                }
            }
        }