using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.AnalysisServices; using Amo=Microsoft.AnalysisServices; namespace BismNormalizer.TabularCompare.MultidimensionalMetadata { /// /// Abstraction of a tabular model relationship with properties and methods for comparison purposes. /// public class Relationship : ITabularObject { private Table _table; private Amo.Relationship _amoRelationship; private string _name; private string _longName; private string _childTableName; private string _childColumnName; private string _parentTableName; private string _parentColumnName; private string _objectDefinition; private bool _copiedFromSource; /// /// Initializes a new instance of the Relationship class using multiple parameters. /// /// Table object that the Relationship belongs to. /// Analysis Management Objects Relationship object abtstracted by the Relationship class. /// Boolean indicating whether the relationship was copied from the source TabularModel object. public Relationship(Table table, Amo.Relationship amoRelationship, bool copiedFromSource = false) { _table = table; _amoRelationship = amoRelationship; // parentTable is actually the FK (child) table in the relationship Dimension dimPK = table.TabularModel.AmoDatabase.Dimensions.Find(amoRelationship.ToRelationshipEnd.DimensionID); _childTableName = table.Name; _childColumnName = table.AmoDimension.Attributes.Find(amoRelationship.FromRelationshipEnd.Attributes[0].AttributeID).Name; _parentTableName = dimPK.Name; _parentColumnName = dimPK.Attributes.Find(amoRelationship.ToRelationshipEnd.Attributes[0].AttributeID).Name; //_name = "'" + _childTableName + "'[" + _childColumnName + "]" + "' -> '" + _parentTableName + "'[" + _parentColumnName + "]"; _name = "'" + _childTableName + "' -> '" + _parentTableName + "'"; _longName = _childTableName + "'[" + _childColumnName + "] => '" + _parentTableName + "'[" + _parentColumnName + "]"; _objectDefinition = "Foreign Key Column: '" + _childTableName + "'[" + _childColumnName + "]\n" + "Primary Key Column: '" + _parentTableName + "'[" + _parentColumnName + "]\n"; _copiedFromSource = copiedFromSource; } /// /// Table object that the Relationship oject belongs to. /// public Table Table => _table; /// /// Analysis Management Objects Relationship object abtstracted by the Relationship class. /// public Amo.Relationship AmoRelationship { get { return _amoRelationship; } set { _amoRelationship = value; } } /// /// Name of the Relationship object. /// public string Name { get { return _name; } set { _name = value; } } /// /// Long name of the Relationship object. /// public string LongName => _longName; /// /// Id of the Relationship object. /// public string Id => _amoRelationship.ID; /// /// Substitute Id of the Relationship object. /// public string SubstituteId => _amoRelationship.ID; /// /// Name of the child table for the Relationship object. /// public string ChildTableName => _childTableName; /// /// Name of the child column for the Relationship object. /// public string ChildColumnName => _childColumnName; /// /// Name of the parent table for the Relationship object. /// public string ParentTableName => _parentTableName; /// /// Name of the parent column for the Relationship object. /// public string ParentColumnName => _parentColumnName; /// /// Indicates whether the Relationship object is active in the tabular model. /// public bool IsActive => _table.TabularModel.ActiveRelationshipIds.Contains(_amoRelationship.ID); /// /// Indicates whether the relationship was copied from the source tabular model. /// public bool CopiedFromSource => _copiedFromSource; /// /// Object definition of the Relationship object. This is a simplified list of relevant attribute values for comparison; not the XMLA definition of the abstracted AMO object. /// public string ObjectDefinition => _objectDefinition; public override string ToString() => this.GetType().FullName; } }