AMO:How to create a dimension in .Net by using AMO





    I am going to build a cube from front end environment for that my first step is am creating a database next am creating a Cube,Data source which is going to help to create a Cube.Till this part am done the coding part.Now my problem is how to create a Dimension in .Net programming.


    Can any one help on this to create a dimensions using code and AMO.



    Thanks in Advance.



    Monday, January 07, 2008 12:06 PM

All replies

  • Hi vishweshwar


    Try the following code. Change appropiate field names by yours Take into account that you need to create Data source view first. Ask me if you want also create DSV-


    Code Block

    Private Shared objDimension As New Dimension
    Private sub CreateDimension()

    ‘Add Dimension to the Database
    objDimension = objDatabase.Dimensions.Add("DimProduct")
    objDimension.Source = New DataSourceViewBinding(objDataSourceView.ID)
    Dim objAttributesColl as DimensionAttributeCollection = objDimension.Attributes

    'Add Dimension Attributes
    Dim objProdKeyAttribute as DimensionAttribute = objAttributesColl.Add("ProductKey")
    Dim objCatKeyAttribute as DimensionAttribute = objAttributesColl.Add("CategoryKey")
    Dim objProdDescAttribute as DimensionAttribute = objAttributesColl.Add("Description")

    'Set Attribute usage and source
    objProdKeyAttribute.Usage = AttributeUsage.Key
    objProdKeyAttribute.KeyColumns.Add("DimProduct","ProductKey", OleDBType.Integer)
    objProdKeyAttribute.NameColumn.Add("DimProduct","ProductName", OleDBType.WChar)
    objCatKeyAttribute.KeyColumns.Add("DimCategory","CategoryKey", OleDBType.Integer) objCatKeyAttribute.NameColumn.Add("DimCategory","CategoryName", OleDBType.WChar)
    objProdDescAttribute.KeyColumns.Add("DimProduct","ProductDesc", OleDBType.WChar)

    'Add Hierarchy and Level
    Dim objHierarchy as Hierarchy = objDimension.Hierarchies.Add ("ProductByCategory")
    objHierarchy.Levels.Add("Category").SourceAttributeID = objCatKeyAttribute.ID
    objHierarchy.Levels.Add("Product").SourceAttributeID = objProdKeyAttribute.ID

    'Add Member Property
    objProdKeyAttribute.AttributeRelationships.Add (objProdDescAttribute.ID)

    End Sub





    Monday, January 07, 2008 6:26 PM
  • Thanks and could you please send me the Code to Create DataSourceView and Creating a Aggregations by using AMO.





    Tuesday, January 08, 2008 9:03 AM
  • Hello,


    here you can find a very good sample to program basic and advanced ssas objects





    Tuesday, January 08, 2008 9:16 AM
  • In the product samples there is a sample called AMOAdventureWorks, which builds a subset of the Adventure Works cube using AMO which should be helpful.


    Tuesday, January 08, 2008 11:22 AM